UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

549 lines (548 loc) 27.5 kB
import { a as getPluginCache, c as getPluginMetadataSnapshotCache, f as withPluginCache, i as createPluginCache, r as bindPluginMetadataSnapshotCache } from "./plugin-cache-DGWspMEc.js"; import { c as isRecord } from "./record-coerce-DItp3I4t.js"; import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CIXf7egm.js"; import { r as normalizeProviderId } from "./provider-id-DMd-TDFp.js"; import { t as pruneMapToMaxSize } from "./map-size-CNcWiFKu.js"; import { t as collectManifestModelIdNormalizationPolicies } from "./provider-model-id-normalization-BFjPahr6.js"; import { n as MANIFEST_KEY } from "./legacy-names-NIXaj2oi.js"; import { i as getActiveDiagnosticsTimelineSpan, s as measureDiagnosticsTimelineSpanSync } from "./diagnostics-timeline-CRX1LXmg.js"; import { _ as resolveInstalledPluginIndexPolicyHash } from "./installed-plugin-index-wrDsjyMD.js"; import { r as official_external_provider_catalog_default } from "./official-external-plugin-bundled-catalogs-dAuKwD3c.js"; import { S as hashJson } from "./discovery-D_VDsZuY.js"; import { t as loadBundledPluginManifestRegistry } from "./manifest-registry-DCCgYk7q.js"; import { d as resolveInstalledPluginIndexStorePath } from "./installed-plugin-index-record-reader-SXWwf_BU.js"; import { a as loadPluginRegistrySnapshotWithMetadata } from "./plugin-registry-snapshot-Dy15Ew18.js"; import { n as resolveInstalledManifestRegistryIndexFingerprint, t as loadPluginManifestRegistryForInstalledIndex } from "./manifest-registry-installed-DdhpzefH.js"; import { d as serializePluginIdScope, f as resolvePluginMetadataEnvFingerprint, i as isCurrentPluginMetadataSnapshotRuntimeGeneration, m as resolvePluginControlPlaneFingerprint, n as getCurrentPluginMetadataSnapshot, u as normalizePluginIdScope } from "./current-plugin-metadata-snapshot-CmSX4G3W.js"; import { r as registerPluginMetadataSnapshotReaders, t as adoptCurrentPluginMetadataSnapshotIfAbsentRuntime } from "./plugin-metadata-snapshot.runtime.js"; //#region src/plugins/official-external-provider-endpoints.ts /** * Provider endpoint metadata for officially externalized provider plugins. * * Endpoint classification (SSRF, attribution, payload-compat policy) keys off * base URLs and must keep working when the owning plugin is not installed: * dist packages exclude externalized plugins, so their manifests are invisible * to bundled discovery. Only the repo-bundled catalog JSON feeds this table; * hosted marketplace feeds must never influence endpoint classification. * Kept separate from official-external-plugin-catalog.ts so provider * transports do not pull the ClawHub install/marketplace module graph. */ /** * Lists manifest-shaped catalog metadata blocks that declare provider endpoints. * * The catalog mirrors manifests faithfully, including endpoint classes core * does not (yet) recognize (e.g. deepinfra-native, gmi-native). The endpoint * reader filters unknown classes exactly as it does for installed manifests, * so they stay inert instead of complicating the mirror contract. */ function listOfficialExternalProviderEndpointManifests() { const entries = official_external_provider_catalog_default.entries; if (!Array.isArray(entries)) return []; const manifests = []; for (const entry of entries) { if (!isRecord(entry)) continue; const manifest = entry[MANIFEST_KEY]; if (isRecord(manifest) && Array.isArray(manifest.providerEndpoints)) manifests.push(manifest); } return manifests; } //#endregion //#region src/plugins/plugin-metadata-provider-facts.ts const PROVIDER_ENDPOINT_CLASSES = new Set("anthropic-public cerebras-native chutes-native deepseek-native github-copilot-native groq-native meta-native mistral-public minimax-native moonshot-native modelstudio-native nvidia-native openai-public openai opencode-native opencode-go-native azure-openai openrouter xai-native xiaomi-native zai-native google-generative-ai google-vertex".split(" ")); function normalizeProviderHosts(value) { return Array.isArray(value) ? value.filter((entry) => typeof entry === "string").map((entry) => entry.trim().toLowerCase()).filter(Boolean) : []; } function normalizePluginProviderBaseUrl(value) { const trimmed = normalizeOptionalString(value); const schemeless = trimmed && /^[a-z0-9.[\]-]+(?::\d+)?(?:[/?#].*)?$/i.test(trimmed); const url = trimmed ? URL.parse(schemeless ? `https://${trimmed}` : trimmed) : null; if (!url || url.protocol !== "http:" && url.protocol !== "https:") return; url.hash = ""; url.search = ""; return normalizeOptionalLowercaseString(url.toString().replace(/\/+$/, "")); } function prepareProviderEndpoints(value) { if (!Array.isArray(value)) return []; return value.filter(isRecord).filter((endpoint) => { const endpointClass = normalizeOptionalString(endpoint.endpointClass); return endpointClass ? PROVIDER_ENDPOINT_CLASSES.has(endpointClass) : false; }).map((endpoint) => { const endpointClass = normalizeOptionalString(endpoint.endpointClass); const googleVertexRegion = normalizeOptionalString(endpoint.googleVertexRegion); const googleVertexRegionHostSuffix = normalizeOptionalString(endpoint.googleVertexRegionHostSuffix)?.toLowerCase(); return Object.assign({ endpointClass, hosts: normalizeProviderHosts(endpoint.hosts), hostSuffixes: normalizeProviderHosts(endpoint.hostSuffixes), baseUrls: normalizeProviderHosts(endpoint.baseUrls).map(normalizePluginProviderBaseUrl).filter((baseUrl) => baseUrl !== void 0) }, googleVertexRegion ? { googleVertexRegion } : {}, googleVertexRegionHostSuffix ? { googleVertexRegionHostSuffix } : {}); }); } const PROVIDER_AUTH_ALIAS_ORIGIN_PRIORITY = { config: 0, bundled: 1, global: 2, workspace: 3 }; /** Prepares package alias candidates without capturing current workspace trust. */ function buildPluginMetadataProviderAuthAliases(plugins) { const aliases = /* @__PURE__ */ new Map(); let order = 0; for (const plugin of plugins) { const entries = [...Object.entries(plugin.providerAuthAliases ?? {}).toSorted(([left], [right]) => left.localeCompare(right)), ...(plugin.providerAuthChoices ?? []).flatMap((choice) => (choice.deprecatedChoiceIds ?? []).map((alias) => [alias, choice.provider]))]; for (const [rawAlias, rawTarget] of entries) { const alias = normalizeProviderId(rawAlias); const target = normalizeProviderId(rawTarget); if (!alias || !target) continue; const candidates = aliases.get(alias) ?? []; candidates.push({ plugin, target, order: order++ }); aliases.set(alias, candidates); } } for (const candidates of aliases.values()) candidates.sort((left, right) => (PROVIDER_AUTH_ALIAS_ORIGIN_PRIORITY[left.plugin.origin] ?? Number.MAX_SAFE_INTEGER) - (PROVIDER_AUTH_ALIAS_ORIGIN_PRIORITY[right.plugin.origin] ?? Number.MAX_SAFE_INTEGER)); return aliases; } function buildPluginMetadataProviderFacts(plugins) { const providerEndpoints = plugins.flatMap((plugin) => prepareProviderEndpoints(plugin.providerEndpoints)); const providerRequests = /* @__PURE__ */ new Map(); for (const plugin of plugins) { const requests = isRecord(plugin.providerRequest?.providers) ? plugin.providerRequest.providers : {}; for (const [rawProvider, request] of Object.entries(requests)) { if (!isRecord(request)) continue; const provider = normalizeLowercaseStringOrEmpty(rawProvider); if (!provider) continue; const supportsStreamingUsage = isRecord(request.openAICompletions) ? request.openAICompletions.supportsStreamingUsage : void 0; providerRequests.set(provider, { ...normalizeOptionalString(request.family) ? { family: normalizeOptionalString(request.family) } : {}, ...normalizeOptionalString(request.compatibilityFamily) === "moonshot" ? { compatibilityFamily: "moonshot" } : {}, ...typeof supportsStreamingUsage === "boolean" ? { openAICompletions: { supportsStreamingUsage } } : {} }); } } for (const manifest of listOfficialExternalProviderEndpointManifests()) providerEndpoints.push(...prepareProviderEndpoints(manifest.providerEndpoints)); return { providerEndpoints, providerRequests, modelIdNormalizationPolicies: collectManifestModelIdNormalizationPolicies(plugins), providerAuthAliases: buildPluginMetadataProviderAuthAliases(plugins) }; } //#endregion //#region src/plugins/plugin-registry-id-normalizer.ts function collectObjectKeys(value) { return value ? Object.keys(value) : []; } function listPluginRegistryNormalizerAliases(plugin) { return [ plugin.id, ...plugin.providers ?? [], ...plugin.channels ?? [], ...plugin.setup?.providers?.map((provider) => provider.id) ?? [], ...plugin.cliBackends ?? [], ...plugin.setup?.cliBackends ?? [], ...collectObjectKeys(plugin.modelCatalog?.providers), ...collectObjectKeys(plugin.modelCatalog?.aliases), ...collectObjectKeys(plugin.providerAuthAliases), ...plugin.legacyPluginIds ?? [] ]; } /** Creates a normalizer that maps provider/channel/catalog aliases back to plugin ids. */ function createPluginRegistryIdNormalizer(index, options = {}) { const aliases = /* @__PURE__ */ new Map(); for (const plugin of index.plugins) { if (!plugin.pluginId) continue; const pluginId = plugin.pluginId.trim(); if (pluginId) aliases.set(pluginId.toLowerCase(), plugin.pluginId); } const registry = options.lookUpTable?.manifestRegistry ?? options.manifestRegistry ?? loadPluginManifestRegistryForInstalledIndex({ index, includeDisabled: true }); for (const plugin of registry.plugins.toSorted((left, right) => left.id.localeCompare(right.id))) { const pluginId = plugin.id.trim(); if (!pluginId) continue; aliases.set(pluginId.toLowerCase(), plugin.id); for (const alias of listPluginRegistryNormalizerAliases(plugin)) { const normalizedAlias = alias.trim(); const normalizedAliasKey = normalizedAlias.toLowerCase(); if (normalizedAlias && !aliases.has(normalizedAliasKey)) aliases.set(normalizedAliasKey, pluginId); } } return (pluginId) => { const trimmed = pluginId.trim(); return aliases.get(trimmed.toLowerCase()) ?? trimmed; }; } //#endregion //#region src/plugins/plugin-metadata-snapshot.ts const MAX_PLUGIN_METADATA_PROJECTIONS = 64; function throwReadonlyPluginMetadataMutation() { throw new TypeError("Plugin metadata snapshots are immutable"); } function freezeSnapshotValue(value, seen = /* @__PURE__ */ new WeakSet()) { if (!value || typeof value !== "object") return value; if (seen.has(value)) return value; seen.add(value); if (value instanceof Map) { for (const [key, entry] of value) { freezeSnapshotValue(key, seen); freezeSnapshotValue(entry, seen); } Object.defineProperties(value, { clear: { value: throwReadonlyPluginMetadataMutation }, delete: { value: throwReadonlyPluginMetadataMutation }, set: { value: throwReadonlyPluginMetadataMutation } }); return Object.freeze(value); } if (value instanceof Set) { for (const entry of value) freezeSnapshotValue(entry, seen); Object.defineProperties(value, { add: { value: throwReadonlyPluginMetadataMutation }, clear: { value: throwReadonlyPluginMetadataMutation }, delete: { value: throwReadonlyPluginMetadataMutation } }); return Object.freeze(value); } for (const entry of Object.values(value)) freezeSnapshotValue(entry, seen); return Object.freeze(value); } function indexesMatch(left, right) { if (!left || !right) return true; return resolveInstalledManifestRegistryIndexFingerprint(left) === resolveInstalledManifestRegistryIndexFingerprint(right); } /** Freezes prepared process-local facts; worker transfers must use restorePluginMetadataSnapshot. */ function finalizePluginMetadataSnapshot(snapshot) { freezeSnapshotValue(snapshot); bindPluginMetadataSnapshotCache(snapshot); return snapshot; } /** Restores process-local behavior and immutability after a snapshot crosses a worker boundary. */ function restorePluginMetadataSnapshot(snapshot) { return finalizePluginMetadataSnapshot({ ...snapshot, normalizePluginId: createPluginRegistryIdNormalizer(snapshot.index, { manifestRegistry: snapshot.manifestRegistry }) }); } function isPluginMetadataSnapshotCompatible(params) { const env = params.env ?? process.env; if (isCurrentPluginMetadataSnapshotRuntimeGeneration(params.snapshot)) return true; const requestedPluginIds = normalizePluginIdScope(params.pluginIds); const snapshotPluginIds = normalizePluginIdScope(params.snapshot.pluginIds); return (snapshotPluginIds === void 0 || params.allowScopedSnapshot === true || requestedPluginIds !== void 0 && serializePluginIdScope(snapshotPluginIds) === serializePluginIdScope(requestedPluginIds)) && params.snapshot.policyHash === resolveInstalledPluginIndexPolicyHash(params.config, env) && (!params.snapshot.configFingerprint || params.snapshot.configFingerprint === resolvePluginControlPlaneFingerprint({ config: params.config, env, index: params.index ?? params.snapshot.index, policyHash: params.snapshot.policyHash, workspaceDir: params.workspaceDir })) && (params.snapshot.workspaceDir ?? "") === (params.workspaceDir ?? "") && indexesMatch(params.snapshot.index, params.index); } function appendOwner(owners, ownedId, pluginId) { const existing = owners.get(ownedId); if (existing) { if (existing.includes(pluginId)) return; existing.push(pluginId); return; } owners.set(ownedId, [pluginId]); } function freezeOwnerMap(owners) { owners.forEach((pluginIds) => Object.freeze(pluginIds)); return owners; } function buildPluginMetadataOwnerMaps(plugins) { const channels = /* @__PURE__ */ new Map(); const channelConfigs = /* @__PURE__ */ new Map(); const providers = /* @__PURE__ */ new Map(); const modelCatalogProviders = /* @__PURE__ */ new Map(); const cliBackends = /* @__PURE__ */ new Map(); const setupProviders = /* @__PURE__ */ new Map(); const commandAliases = /* @__PURE__ */ new Map(); const contracts = /* @__PURE__ */ new Map(); for (const plugin of plugins) { for (const channelId of plugin.channels ?? []) appendOwner(channels, channelId, plugin.id); for (const channelId of Object.keys(plugin.channelConfigs ?? {})) appendOwner(channelConfigs, channelId, plugin.id); for (const providerId of plugin.providers ?? []) appendOwner(providers, providerId, plugin.id); for (const [rawAlias, target] of Object.entries(plugin.providerAuthAliases ?? {})) { const alias = normalizeProviderId(rawAlias); const targetProvider = normalizeProviderId(target); if (alias && targetProvider && (plugin.providers ?? []).some((providerId) => normalizeProviderId(providerId) === targetProvider)) appendOwner(providers, alias, plugin.id); } for (const providerId of Object.keys(plugin.modelCatalog?.providers ?? {})) appendOwner(modelCatalogProviders, providerId, plugin.id); for (const providerId of Object.keys(plugin.modelCatalog?.aliases ?? {})) appendOwner(modelCatalogProviders, providerId, plugin.id); for (const cliBackendId of plugin.cliBackends ?? []) appendOwner(cliBackends, normalizeProviderId(cliBackendId), plugin.id); for (const cliBackendId of plugin.setup?.cliBackends ?? []) appendOwner(cliBackends, normalizeProviderId(cliBackendId), plugin.id); for (const setupProvider of plugin.setup?.providers ?? []) appendOwner(setupProviders, setupProvider.id, plugin.id); for (const commandAlias of plugin.commandAliases ?? []) appendOwner(commandAliases, commandAlias.name, plugin.id); for (const [contract, values] of Object.entries(plugin.contracts ?? {})) if (Array.isArray(values) && values.length > 0) appendOwner(contracts, contract, plugin.id); } return { channels: freezeOwnerMap(channels), channelConfigs: freezeOwnerMap(channelConfigs), providers: freezeOwnerMap(providers), modelCatalogProviders: freezeOwnerMap(modelCatalogProviders), cliBackends: freezeOwnerMap(cliBackends), setupProviders: freezeOwnerMap(setupProviders), commandAliases: freezeOwnerMap(commandAliases), contracts: freezeOwnerMap(contracts), ...buildPluginMetadataProviderFacts(plugins) }; } function listPluginOriginsFromMetadataSnapshot(snapshot) { return new Map(snapshot.plugins.map((record) => [record.id, record.origin])); } /** Rebuilds every manifest-derived snapshot fact from one authoritative registry. */ function rebasePluginMetadataSnapshotManifestRegistry(snapshot, manifestRegistry) { const plugins = manifestRegistry.plugins; const rebased = { ...snapshot, manifestRegistry, plugins, diagnostics: manifestRegistry.diagnostics, byPluginId: new Map(plugins.map((plugin) => [plugin.id, plugin])), normalizePluginId: snapshot.index ? createPluginRegistryIdNormalizer(snapshot.index, { manifestRegistry }) : snapshot.normalizePluginId, owners: buildPluginMetadataOwnerMaps(plugins), ...snapshot.metrics ? { metrics: { ...snapshot.metrics, manifestPluginCount: plugins.length } } : {} }; bindPluginMetadataSnapshotCache(rebased, getPluginMetadataSnapshotCache(snapshot)); return rebased; } function projectPluginMetadataSnapshot(snapshot, pluginIds) { const selectedIds = normalizePluginIdScope(pluginIds); if (selectedIds === void 0) return snapshot; const key = serializePluginIdScope(selectedIds); if (key === serializePluginIdScope(snapshot.pluginIds)) return snapshot; const cache = getPluginMetadataSnapshotCache(snapshot); let selections = cache.metadata.projections.get(snapshot); if (!selections) { selections = /* @__PURE__ */ new Map(); cache.metadata.projections.set(snapshot, selections); } const cached = selections.get(key); if (cached) return cached; const selected = new Set(selectedIds); const projected = freezeSnapshotValue({ ...rebasePluginMetadataSnapshotManifestRegistry(snapshot, { plugins: snapshot.plugins.filter((plugin) => selected.has(plugin.id)), diagnostics: snapshot.manifestRegistry.diagnostics }), pluginIds: selectedIds }); bindPluginMetadataSnapshotCache(projected, cache); cache.metadata.projectionSources.set(projected, snapshot); selections.set(key, projected); pruneMapToMaxSize(selections, MAX_PLUGIN_METADATA_PROJECTIONS); return projected; } /** Uses semantic inputs only: checking freshness here would defeat first-access reuse. */ function resolvePluginMetadataSnapshotCacheKey(params) { return hashJson({ env: resolvePluginMetadataEnvFingerprint(params.env ?? process.env), policy: resolveInstalledPluginIndexPolicyHash(params.config, params.env), loadPaths: params.config?.plugins?.load?.paths, workspaceDir: params.workspaceDir, stateDir: params.stateDir, index: params.index ? resolveInstalledManifestRegistryIndexFingerprint(params.index) : void 0, preferPersisted: params.preferPersisted !== false }); } function loadPluginMetadataSnapshot(params) { if (params.allowCurrent === false && getPluginCache().kind !== "operation") return withPluginCache(createPluginCache(), () => loadPluginMetadataSnapshot(params)); if (params.allowCurrent !== false && params.stateDir === void 0 && params.preferPersisted !== false) { const current = getCurrentPluginMetadataSnapshot({ config: params.config, env: params.env, workspaceDir: params.workspaceDir, allowWorkspaceScopedSnapshot: true }); if (current && (isCurrentPluginMetadataSnapshotRuntimeGeneration(current) || isPluginMetadataSnapshotCompatible({ snapshot: current, config: params.config, env: params.env, workspaceDir: params.workspaceDir, index: params.index }))) return projectPluginMetadataSnapshot(current, params.pluginIds ?? params.pluginIdScope?.resolve({ index: current.index })); } const cache = getPluginCache(); const key = resolvePluginMetadataSnapshotCacheKey(params); const cached = cache.metadata.snapshots.get(key); if (cached) return projectPluginMetadataSnapshot(cached, params.pluginIds ?? params.pluginIdScope?.resolve({ index: cached.index })); const activeTimelineSpan = getActiveDiagnosticsTimelineSpan(); const snapshot = measureDiagnosticsTimelineSpanSync("plugins.metadata.scan", () => loadPluginMetadataSnapshotImpl(params), { phase: activeTimelineSpan?.phase ?? "startup", config: params.config, env: params.env, attributes: { hasWorkspaceDir: params.workspaceDir !== void 0, hasInstalledIndex: params.index !== void 0 } }); const frozen = measureDiagnosticsTimelineSpanSync("plugins.metadata.freeze", () => restorePluginMetadataSnapshot(snapshot), { phase: activeTimelineSpan?.phase ?? "startup", config: params.config, env: params.env, attributes: { indexPluginCount: snapshot.index.plugins.length, manifestPluginCount: snapshot.plugins.length } }); cache.metadata.snapshots.set(key, frozen); return projectPluginMetadataSnapshot(frozen, params.pluginIds ?? params.pluginIdScope?.resolve({ index: frozen.index })); } /** Promotes a planning-scoped graph to the complete process-lifecycle metadata snapshot. */ function completePluginMetadataSnapshot(params) { if (!params.snapshot || params.snapshot.pluginIds === void 0 && params.snapshot.bundledManifestRegistry) return params.snapshot; const snapshot = params.snapshot; const cache = getPluginMetadataSnapshotCache(snapshot); const cached = cache.metadata.completions.get(snapshot); if (cached) return cached; const source = cache.metadata.projectionSources.get(snapshot); if (source) { const completed = completePluginMetadataSnapshot({ ...params, snapshot: source }); if (completed) cache.metadata.completions.set(snapshot, completed); return completed; } return withPluginCache(cache, () => { const inputs = { ...params, snapshot }; const workspaceDir = inputs.workspaceDir ?? inputs.snapshot.workspaceDir; const manifestStartedAt = performance.now(); const manifestRegistry = inputs.snapshot.pluginIds === void 0 ? inputs.snapshot.manifestRegistry : loadPluginManifestRegistryForInstalledIndex({ index: inputs.snapshot.index, config: inputs.config, env: inputs.env ?? process.env, ...workspaceDir ? { workspaceDir } : {}, includeDisabled: true }); const bundledManifestRegistry = inputs.snapshot.bundledManifestRegistry ?? loadBundledPluginManifestRegistry({ env: inputs.env }); const manifestRegistryMs = performance.now() - manifestStartedAt; const rebased = rebasePluginMetadataSnapshotManifestRegistry(inputs.snapshot, manifestRegistry); const { pluginIds: _pluginIds, ...unscoped } = rebased; const completed = finalizePluginMetadataSnapshot({ ...unscoped, bundledManifestRegistry, configFingerprint: resolvePluginControlPlaneFingerprint({ config: inputs.config, env: inputs.env, index: rebased.index, policyHash: rebased.policyHash, workspaceDir }), metrics: { ...rebased.metrics, manifestRegistryMs, totalMs: rebased.metrics.totalMs + manifestRegistryMs } }); cache.metadata.completions.set(snapshot, completed); return completed; }); } function resolvePluginMetadataSnapshot(params) { if (params.allowCurrent !== false && params.stateDir === void 0 && params.preferPersisted !== false) { const current = getCurrentPluginMetadataSnapshot({ config: params.config, env: params.env, ...params.config === void 0 ? { requireDefaultDiscoveryContext: true } : {}, ...params.pluginIds !== void 0 ? { pluginIds: params.pluginIds } : {}, ...params.pluginIdScope !== void 0 ? { pluginIdScope: params.pluginIdScope } : {}, ...params.workspaceDir !== void 0 ? { workspaceDir: params.workspaceDir } : {}, ...params.allowWorkspaceScopedCurrent === true ? { allowWorkspaceScopedSnapshot: true } : {} }); if (!current) { const snapshot = loadPluginMetadataSnapshot(params); if (params.index === void 0 && params.workspaceDir === void 0 && params.pluginIds === void 0 && params.pluginIdScope === void 0 && snapshot.workspaceDir === void 0 && snapshot.pluginIds === void 0) adoptCurrentPluginMetadataSnapshotIfAbsentRuntime(snapshot, params); return snapshot; } if (isCurrentPluginMetadataSnapshotRuntimeGeneration(current)) return projectPluginMetadataSnapshot(current, params.pluginIds ?? params.pluginIdScope?.resolve({ index: current.index })); if (!params.index) return current; if (isPluginMetadataSnapshotCompatible({ snapshot: current, config: params.config, env: params.env, allowScopedSnapshot: params.pluginIds !== void 0 || params.pluginIdScope !== void 0, workspaceDir: params.workspaceDir ?? (params.allowWorkspaceScopedCurrent === true ? current.workspaceDir : void 0), index: params.index })) return current; } return loadPluginMetadataSnapshot(params); } function loadPluginMetadataSnapshotImpl(params) { const totalStartedAt = performance.now(); const registryStartedAt = performance.now(); const registryResult = loadPluginRegistrySnapshotWithMetadata({ config: params.config, workspaceDir: params.workspaceDir, ...params.stateDir ? { stateDir: params.stateDir } : {}, env: params.env, ...params.preferPersisted !== void 0 ? { preferPersisted: params.preferPersisted } : {}, ...params.allowCurrent !== void 0 ? { allowCurrent: params.allowCurrent } : {}, ...params.index ? { index: params.index } : {} }); const registrySnapshotMs = performance.now() - registryStartedAt; const index = structuredClone(registryResult.snapshot); index.diagnostics ??= []; const manifestStartedAt = performance.now(); const manifestRegistry = loadPluginManifestRegistryForInstalledIndex({ index, registryPath: resolveInstalledPluginIndexStorePath({ env: params.env, stateDir: params.stateDir }), ...registryResult.manifestRegistry ? { manifestRegistry: registryResult.manifestRegistry } : {}, config: params.config, workspaceDir: params.workspaceDir, env: params.env, includeDisabled: true }); const manifestRegistryMs = performance.now() - manifestStartedAt; const byPluginId = new Map(manifestRegistry.plugins.map((plugin) => [plugin.id, plugin])); const ownerMapsStartedAt = performance.now(); const owners = buildPluginMetadataOwnerMaps(manifestRegistry.plugins); const ownerMapsMs = performance.now() - ownerMapsStartedAt; const totalMs = performance.now() - totalStartedAt; return { policyHash: index.policyHash, registrySource: registryResult.source, configFingerprint: resolvePluginControlPlaneFingerprint({ config: params.config, env: params.env, index, policyHash: index.policyHash, workspaceDir: params.workspaceDir }), ...params.workspaceDir ? { workspaceDir: params.workspaceDir } : {}, index, registryIndex: index, registryDiagnostics: registryResult.diagnostics, manifestRegistry, plugins: manifestRegistry.plugins, diagnostics: manifestRegistry.diagnostics, byPluginId, owners, metrics: { registrySnapshotMs, manifestRegistryMs, ownerMapsMs, totalMs, indexPluginCount: index.plugins.length, manifestPluginCount: manifestRegistry.plugins.length }, discovery: registryResult.discovery }; } registerPluginMetadataSnapshotReaders({ resolvePluginMetadataSnapshot }); //#endregion export { loadPluginMetadataSnapshot as a, resolvePluginMetadataSnapshot as c, createPluginRegistryIdNormalizer as d, buildPluginMetadataProviderAuthAliases as f, listPluginOriginsFromMetadataSnapshot as i, resolvePluginMetadataSnapshotCacheKey as l, finalizePluginMetadataSnapshot as n, projectPluginMetadataSnapshot as o, normalizePluginProviderBaseUrl as p, isPluginMetadataSnapshotCompatible as r, rebasePluginMetadataSnapshotManifestRegistry as s, completePluginMetadataSnapshot as t, restorePluginMetadataSnapshot as u };