{"version":3,"file":"load.cjs","names":["AsyncLocalStorage","dirname","join","existsSync","resolve","pathToFileURL","AppDescriptorSchema","resolveApp","toConfigInput","Schema","isPlainObject","bosConfigMerger","isAbsolute","resolveExtendsRef","fetchBosConfigFromFastKv","readFileSync"],"sources":["../../../src/services/resolution/load.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { Schema } from \"effect\";\nimport { resolveApp, toConfigInput } from \"../../descriptor/resolve\";\nimport { type AppDescriptor, AppDescriptorSchema } from \"../../descriptor/schema\";\nimport type { BosConfig, BosConfigInput, BosPluginRef } from \"../../types\";\nimport { fetchBosConfigFromFastKv } from \"../registry/fastkv\";\nimport { type BosEnv, bosConfigMerger, isPlainObject, resolveExtendsRef } from \"./merge\";\n\nexport const LOCAL_PREFIX = \"local:\";\nexport const MISSING_CONFIG_MESSAGE = \"No config found (bos.app.ts or bos.config.json)\";\n\nexport const DEV_OVERLAY_FILENAME = \"bos.dev.ts\";\n\ninterface ConfigWarningCapture {\n  sink: string[];\n  previous: ConfigWarningCapture | undefined;\n}\n\nconst warningCapture = new AsyncLocalStorage<ConfigWarningCapture | undefined>();\n\n/**\n * @internal — runs `fn` with config warnings captured into `sink` instead of\n * the console. Plumbing for the resolution session; not part of the public\n * config surface.\n */\nexport function runWithConfigWarningSink<T>(sink: string[], fn: () => T): T {\n  return warningCapture.run({ sink, previous: warningCapture.getStore() }, fn);\n}\n\nexport function emitConfigWarning(message: string): void {\n  const capture = warningCapture.getStore();\n  if (capture) {\n    capture.sink.push(message);\n  } else {\n    console.warn(message);\n  }\n}\n\nconst configPathCache = new Map<string, string | null>();\n\n/**\n * @internal — clears the findConfigPath memo. Plumbing for tests and the\n * resolution session; not part of the public config surface.\n */\nexport function resetConfigPathCache(): void {\n  configPathCache.clear();\n}\n\n/**\n * Reads the local authored config without resolving the extends chain or\n * touching the network — the build-surface factories (generated rsbuild\n * configs) consume it for their APP_NAME/APP_ACCOUNT defines.\n */\nexport async function readAuthoredConfigInput(cwd?: string): Promise<BosConfigInput | null> {\n  const configPath = findConfigPath(cwd);\n  if (!configPath || configPath.startsWith(\"bos://\")) return null;\n  return readConfigInput(configPath, dirname(configPath));\n}\n\n/**\n * The authored config entry inside exactly `dir` — no upward walk. Unlike\n * `findConfigPath` this never escapes the given directory, for write targets\n * and nested-local-path resolution where a parent's config must not be\n * picked up. Prefers the authored `bos.app.ts` descriptor (the canonical\n * form) over a legacy `bos.config.json`.\n */\nexport function localConfigEntryPath(dir: string): string | null {\n  const appPath = join(dir, \"bos.app.ts\");\n  if (existsSync(appPath)) return appPath;\n  const jsonPath = join(dir, \"bos.config.json\");\n  return existsSync(jsonPath) ? jsonPath : null;\n}\n\n/** `localConfigEntryPath` + the form-aware read (`BosConfigInput`). */\nexport async function readLocalAuthoredConfigInput(dir: string): Promise<BosConfigInput | null> {\n  const entry = localConfigEntryPath(dir);\n  if (!entry) return null;\n  return readConfigInput(entry, dirname(entry));\n}\n\n/**\n * The authored `bos.app.ts` descriptor is the canonical form — when both\n * forms coexist (e.g. a generated `bos.config.json` write-back beside the\n * authored descriptor), the authored file wins. JSON-form-only children are\n * unaffected: with no `bos.app.ts`, the JSON file is the entry.\n */\nexport function findConfigPath(cwd?: string): string | null {\n  const cacheKey = resolve(cwd ?? process.cwd());\n  const cached = configPathCache.get(cacheKey);\n  if (cached !== undefined) return cached;\n\n  let dir = cacheKey;\n  while (true) {\n    const appPath = join(dir, \"bos.app.ts\");\n    if (existsSync(appPath)) {\n      configPathCache.set(cacheKey, appPath);\n      return appPath;\n    }\n    const jsonPath = join(dir, \"bos.config.json\");\n    if (existsSync(jsonPath)) {\n      configPathCache.set(cacheKey, jsonPath);\n      return jsonPath;\n    }\n    const parent = dirname(dir);\n    if (parent === dir) break;\n    dir = parent;\n  }\n  configPathCache.set(cacheKey, null);\n  return null;\n}\n\nexport function isAppDescriptorPath(configPath: string): boolean {\n  return configPath.endsWith(\".app.ts\") || configPath.endsWith(\".app.js\");\n}\n\n/**\n * Materialize an authored bos.app.ts descriptor into the authoring-shape\n * `BosConfigInput` the config pipeline consumes. Import-extends is honored\n * two ways: the parent descriptor value can be imported directly (an\n * inlined parent, resolved through `resolveApp`), or `extends` can name a\n * published config (`bos://…`) / a local file, which flows into the JSON\n * extends chain unchanged.\n */\nexport async function loadAppDescriptorConfig(resolvedPath: string): Promise<BosConfigInput> {\n  // webpackIgnore: the path is inherently runtime-resolved — bundlers must\n  // not try to statically analyze it (rsbuild otherwise warns \"Critical\n  // dependency: the request of a dependency is an expression\").\n  const mod = (await import(/* webpackIgnore: true */ pathToFileURL(resolvedPath).href)) as Record<\n    string,\n    unknown\n  >;\n  return parseAppDescriptorModule(mod, resolvedPath);\n}\n\n/**\n * Evaluate an authored descriptor's source text in-process: descriptor-constructor\n * imports (`App`/`API`/`UI`/`Plugin` from `everything-dev/descriptor`) are\n * stubbed with pure-identity shims and the remaining module body is imported\n * from a data URL. Byte-deterministic — no bundler resolution of the\n * descriptor package and no module-cache interference (a tempdir child has no\n * node_modules, so a real dynamic import is both fragile and here served\n * stale, mangled transforms under vitest).\n */\nexport async function loadInProcessDescriptor(\n  source: string,\n  label: string,\n): Promise<BosConfigInput> {\n  const body = source\n    .split(\"\\n\")\n    .filter((line) => !/^\\s*import\\b/.test(line))\n    .join(\"\\n\");\n  const shims = [\n    \"const App = (input) => input;\",\n    \"const API = (input) => input;\",\n    \"const UI = (input) => input;\",\n    \"const Plugin = (name) => ({ path: (dir, extra = {}) => ({ ...extra, name, path: dir }), extends: (ref, extra = {}) => ({ ...extra, name, extends: ref }) });\",\n  ].join(\"\\n\");\n  const encoded = Buffer.from(`${shims}\\n${body}`, \"utf-8\").toString(\"base64\");\n  // webpackIgnore: the data URL is runtime-resolved (Node imports it natively)\n  // — bundlers must not try to statically analyze the specifier (rspack\n  // otherwise fails the dist build with \"Can't resolve 'data:text'\").\n  const mod = (await import(\n    /* webpackIgnore: true */ `data:text/javascript;base64,${encoded}`\n  )) as Record<string, unknown>;\n  return parseAppDescriptorModule(mod, label);\n}\n\n/**\n * @internal — parses an already-imported app descriptor module into the\n * authoring-shape `BosConfigInput`. Plumbing for the resolution session's\n * injectable module loader; not part of the public config surface.\n */\nexport function parseAppDescriptorModule(\n  mod: Record<string, unknown>,\n  sourcePath?: string,\n): BosConfigInput {\n  if (!mod.default) {\n    throw new Error(\n      `${sourcePath ?? \"App descriptor module\"} must default-export an App() descriptor`,\n    );\n  }\n  const descriptor = AppDescriptorSchema.parse(mod.default);\n\n  // Registry candidates: named exports that parse as App descriptors.\n  const registry: Record<string, unknown> = {};\n  for (const value of Object.values(mod)) {\n    const parsed = AppDescriptorSchema.safeParse(value);\n    if (parsed.success) registry[parsed.data.name] = parsed.data;\n  }\n\n  const extendsRef = descriptor.extends;\n  const inRegistry = typeof extendsRef === \"string\" && registry[extendsRef] !== undefined;\n  const importedParent = extendsRef !== undefined && typeof extendsRef !== \"string\";\n\n  if (inRegistry || importedParent) {\n    return resolveApp(descriptor.name, registry as never);\n  }\n\n  const input = toConfigInput(descriptor);\n  if (extendsRef !== undefined) {\n    input.extends = extendsRef as BosConfigInput[\"extends\"];\n  }\n  return input;\n}\n\n/**\n * @internal — validates an already-imported `bos.dev.ts` module as a\n * `Partial<AppDescriptor>` dev overlay. Plumbing for the resolution session's\n * injectable module loader; not part of the public config surface.\n */\nexport function parseDevOverlayModule(\n  mod: Record<string, unknown>,\n  sourcePath?: string,\n): Partial<AppDescriptor> {\n  const source = sourcePath ?? DEV_OVERLAY_FILENAME;\n  if (!mod?.default) {\n    throw new DevOverlayError({\n      path: source,\n      message: `${source} must default-export a dev overlay (Partial<AppDescriptor>)`,\n    });\n  }\n  const parsed = AppDescriptorSchema.partial().safeParse(mod.default);\n  if (!parsed.success) {\n    throw new DevOverlayError({\n      path: source,\n      message: `${source} is not a valid dev overlay: ${parsed.error.message}`,\n      cause: parsed.error,\n    });\n  }\n  return parsed.data;\n}\n\nexport interface ResolvedComposableReference {\n  entry: BosPluginRef;\n  providerBaseDir: string;\n  targetPath: string;\n  associatedUi?: Record<string, unknown>;\n}\n\ninterface ParsedExtendsTarget {\n  configPath: string;\n  targetPath?: string;\n}\n\nexport class ConfigLoadError extends Schema.TaggedError<ConfigLoadError>()(\"ConfigLoadError\", {\n  path: Schema.String,\n  message: Schema.String,\n  cause: Schema.optional(Schema.Unknown),\n}) {}\n\nexport class CircularExtendsError extends Schema.TaggedError<CircularExtendsError>()(\n  \"CircularExtendsError\",\n  { chain: Schema.Array(Schema.String), message: Schema.String },\n) {}\n\nexport class ConfigNotfoundError extends Schema.TaggedError<ConfigNotfoundError>()(\n  \"ConfigNotfoundError\",\n  { message: Schema.String },\n) {}\n\nexport class ConfigExtendsError extends Schema.TaggedError<ConfigExtendsError>()(\n  \"ConfigExtendsError\",\n  {\n    message: Schema.String,\n    cause: Schema.optional(Schema.Unknown),\n  },\n) {}\n\nexport class ConfigVersionManifestError extends Schema.TaggedError<ConfigVersionManifestError>()(\n  \"ConfigVersionManifestError\",\n  {\n    message: Schema.String,\n    cause: Schema.optional(Schema.Unknown),\n  },\n) {}\n\nexport class DevOverlayError extends Schema.TaggedError<DevOverlayError>()(\"DevOverlayError\", {\n  path: Schema.String,\n  message: Schema.String,\n  cause: Schema.optional(Schema.Unknown),\n}) {}\n\nexport function defaultConfigEnv(): BosEnv {\n  return process.env.NODE_ENV === \"production\" ? \"production\" : \"development\";\n}\n\nexport function getEntryAssociatedUi(\n  entry: Partial<BosPluginRef>,\n): Record<string, unknown> | undefined {\n  const flat = isPlainObject(entry.ui) ? (entry.ui as Record<string, unknown>) : undefined;\n  const nested = (() => {\n    if (!isPlainObject(entry.app)) return undefined;\n    const app = entry.app as Record<string, unknown>;\n    return isPlainObject(app.ui) ? (app.ui as Record<string, unknown>) : undefined;\n  })();\n  const ui = flat ?? nested;\n  if (!ui) return undefined;\n\n  if (\"shared\" in ui) {\n    throw new ConfigExtendsError({\n      message:\n        \"app.ui.shared is no longer supported. Move shared deps to app.api.shared, app.auth.shared, or plugins.*.shared.\",\n    });\n  }\n\n  return ui;\n}\n\nfunction mergeAssociatedUi(\n  parentUi: Record<string, unknown> | undefined,\n  childUi: Record<string, unknown> | undefined,\n): Record<string, unknown> | undefined {\n  if (!parentUi) {\n    return childUi ? { ...childUi } : undefined;\n  }\n\n  if (!childUi) {\n    return { ...parentUi };\n  }\n\n  return bosConfigMerger({ ...childUi }, parentUi) as Record<string, unknown>;\n}\n\nfunction withAssociatedUi(\n  entry: BosPluginRef,\n  associatedUi?: Record<string, unknown>,\n): BosPluginRef {\n  if (!associatedUi) {\n    return entry;\n  }\n\n  const app = isPlainObject(entry.app)\n    ? ({ ...(entry.app as Record<string, unknown>) } as Record<string, unknown>)\n    : {};\n  app.ui = mergeAssociatedUi(getEntryAssociatedUi(entry), associatedUi);\n\n  return {\n    ...entry,\n    app,\n  };\n}\n\nexport async function resolveConfigComposableEntries(\n  config: BosConfig,\n  baseDir: string,\n  env: BosEnv,\n): Promise<BosConfig> {\n  const [resolvedApi, resolvedAuth] = await Promise.all([\n    resolveComposableReference(config.app.api as BosPluginRef, baseDir, env, \"app.api\"),\n    config.app.auth\n      ? resolveComposableReference(config.app.auth as BosPluginRef, baseDir, env, \"app.auth\")\n      : Promise.resolve(undefined),\n  ]);\n\n  const resolvedPlugins = config.plugins\n    ? Object.fromEntries(\n        await Promise.all(\n          Object.entries(config.plugins).map(async ([pluginId, pluginValue]) => {\n            const resolvedPlugin = await resolveComposableReference(\n              asComposableEntry(pluginValue),\n              baseDir,\n              env,\n              `plugins.${pluginId}`,\n            );\n\n            return [\n              pluginId,\n              withAssociatedUi(resolvedPlugin.entry, resolvedPlugin.associatedUi),\n            ] as const;\n          }),\n        ),\n      )\n    : undefined;\n\n  return {\n    ...config,\n    app: {\n      ...config.app,\n      api: resolvedApi.entry,\n      auth: resolvedAuth?.entry,\n    },\n    plugins: resolvedPlugins,\n  };\n}\n\n/**\n * @internal — splits an extends ref into its config path and optional\n * `#target` suffix. Plumbing for the resolution session; not part of the\n * public config surface.\n */\nexport function parseExtendsTarget(ref: string): ParsedExtendsTarget {\n  const hashIndex = ref.indexOf(\"#\");\n  if (hashIndex === -1) {\n    return { configPath: ref };\n  }\n\n  const configPath = ref.slice(0, hashIndex);\n  const targetPath = ref.slice(hashIndex + 1);\n  return {\n    configPath,\n    targetPath: targetPath.length > 0 ? targetPath : undefined,\n  };\n}\n\n/**\n * @internal — resolves the base directory a config path extends from.\n * Plumbing for the resolution session; not part of the public config surface.\n */\nexport function getConfigBaseDir(configPath: string, baseDir: string): string {\n  if (configPath.startsWith(\"bos://\")) return baseDir;\n  return dirname(isAbsolute(configPath) ? configPath : resolve(baseDir, configPath));\n}\n\nfunction asComposableEntry(value: unknown): BosPluginRef {\n  if (value === undefined) {\n    return {};\n  }\n  if (typeof value === \"string\") {\n    return { extends: value };\n  }\n  if (!isPlainObject(value)) {\n    throw new ConfigExtendsError({\n      message: `Expected config entry object, received ${typeof value}`,\n    });\n  }\n  return value as BosPluginRef;\n}\n\nfunction getTargetedEntry(config: BosConfigInput, targetPath: string): BosPluginRef {\n  if (targetPath.startsWith(\"app.\")) {\n    const entryKey = targetPath.slice(\"app.\".length);\n    return asComposableEntry(config.app?.[entryKey]);\n  }\n\n  if (targetPath.startsWith(\"plugins.\")) {\n    const pluginId = targetPath.slice(\"plugins.\".length);\n    if (pluginId.length === 0) {\n      throw new ConfigExtendsError({ message: `Invalid plugin target path: ${targetPath}` });\n    }\n    return asComposableEntry(config.plugins?.[pluginId]);\n  }\n\n  throw new ConfigExtendsError({ message: `Unsupported extends target path: ${targetPath}` });\n}\n\nfunction getAssociatedUi(\n  config: BosConfigInput,\n  _targetPath: string,\n): Record<string, unknown> | undefined {\n  if (!isPlainObject(config.app?.ui)) {\n    return undefined;\n  }\n\n  const ui = config.app.ui as Record<string, unknown>;\n  if (\"shared\" in ui) {\n    throw new ConfigExtendsError({\n      message:\n        \"app.ui.shared is no longer supported. Move shared deps to app.api.shared, app.auth.shared, or plugins.*.shared.\",\n    });\n  }\n\n  return ui;\n}\n\nfunction applyNullOverrides(\n  target: Record<string, unknown>,\n  source: Record<string, unknown>,\n): void {\n  for (const [key, value] of Object.entries(source)) {\n    if (value === null) {\n      target[key] = null;\n    } else if (isPlainObject(value) && isPlainObject(target[key])) {\n      applyNullOverrides(target[key] as Record<string, unknown>, value as Record<string, unknown>);\n    }\n  }\n}\n\nfunction mergeComposableEntries(\n  parent: Partial<BosPluginRef>,\n  child: Partial<BosPluginRef>,\n): BosPluginRef {\n  const merged = bosConfigMerger({ ...child }, parent) as Record<string, unknown>;\n  applyNullOverrides(merged, child as Record<string, unknown>);\n  return merged as BosPluginRef;\n}\n\nfunction stripUnsafeLocalDevelopment<T extends Record<string, unknown> | undefined>(\n  entry: T,\n  allowLocalPaths: boolean,\n): T {\n  if (!entry || allowLocalPaths) {\n    return entry;\n  }\n\n  if (typeof entry.development === \"string\" && entry.development.startsWith(LOCAL_PREFIX)) {\n    const { development: _ignored, ...rest } = entry;\n    return rest as T;\n  }\n\n  return entry;\n}\n\nexport async function resolveComposableReference(\n  source: BosPluginRef,\n  baseDir: string,\n  env: BosEnv,\n  defaultTargetPath: string,\n): Promise<ResolvedComposableReference> {\n  let resolvedEntry: BosPluginRef = {};\n  let providerBaseDir = baseDir;\n  let targetPath = defaultTargetPath;\n  let associatedUi = getEntryAssociatedUi(source);\n  let allowLocalPaths = false;\n  let extendsError: unknown;\n\n  const extendsRef = source.extends ? resolveExtendsRef(source.extends, env) : undefined;\n  if (extendsRef) {\n    const { resolveMergedConfigInput } = await import(\"./session\");\n    const parsed = parseExtendsTarget(extendsRef);\n    targetPath = parsed.targetPath ?? defaultTargetPath;\n    const extendsBaseDir = getConfigBaseDir(parsed.configPath, baseDir);\n    try {\n      const extendedConfig = await resolveMergedConfigInput(parsed.configPath, {\n        baseDir: extendsBaseDir,\n        env,\n      });\n      resolvedEntry = mergeComposableEntries(\n        resolvedEntry,\n        getTargetedEntry(extendedConfig, targetPath),\n      );\n      providerBaseDir = extendsBaseDir;\n      associatedUi = mergeAssociatedUi(associatedUi, getAssociatedUi(extendedConfig, targetPath));\n    } catch (error) {\n      extendsError = error;\n    }\n  }\n\n  const localDevelopment =\n    typeof source.development === \"string\" && source.development.startsWith(LOCAL_PREFIX)\n      ? source.development\n      : undefined;\n  const localDevelopmentPath = localDevelopment\n    ? resolve(baseDir, localDevelopment.slice(LOCAL_PREFIX.length).trim())\n    : undefined;\n  const hasUsableLocalDevelopment = Boolean(\n    localDevelopmentPath && existsSync(localDevelopmentPath),\n  );\n\n  if (localDevelopmentPath) {\n    const { resolveMergedConfigInput } = await import(\"./session\");\n    const localPath = localDevelopmentPath;\n    const localConfigPath = localConfigEntryPath(localPath);\n    if (localConfigPath) {\n      const localConfig = await resolveMergedConfigInput(localConfigPath, {\n        baseDir: localPath,\n        env,\n      });\n      resolvedEntry = mergeComposableEntries(\n        resolvedEntry,\n        getTargetedEntry(localConfig, targetPath),\n      );\n      providerBaseDir = localPath;\n      associatedUi = mergeAssociatedUi(associatedUi, getAssociatedUi(localConfig, targetPath));\n      allowLocalPaths = true;\n    }\n  }\n\n  const sourceOverrides = { ...source };\n  if (allowLocalPaths && localDevelopment) {\n    delete sourceOverrides.development;\n  }\n\n  resolvedEntry = mergeComposableEntries(resolvedEntry, sourceOverrides);\n  associatedUi = mergeAssociatedUi(associatedUi, getEntryAssociatedUi(sourceOverrides));\n\n  if (extendsError && !allowLocalPaths && !hasUsableLocalDevelopment) {\n    throw extendsError;\n  }\n\n  return {\n    entry: stripUnsafeLocalDevelopment(resolvedEntry, allowLocalPaths || Boolean(localDevelopment)),\n    providerBaseDir,\n    targetPath,\n    // A plugin's own ui lives under its local development tree — the same\n    // safety argument as the entry itself: keep its local target when the\n    // plugin resolves locally, or the folder-form ui surface silently\n    // disappears (no BOS_UI_PORT, an unassigned ui dev server, and a\n    // port collision with another plugin's ui slot).\n    associatedUi: stripUnsafeLocalDevelopment(\n      associatedUi,\n      allowLocalPaths || Boolean(localDevelopment),\n    ),\n  };\n}\n\nasync function readConfigInput(configPath: string, baseDir: string): Promise<BosConfigInput> {\n  if (configPath.startsWith(\"bos://\")) {\n    return fetchBosConfigFromFastKv<BosConfigInput>(configPath);\n  }\n\n  const resolvedPath = isAbsolute(configPath) ? configPath : resolve(baseDir, configPath);\n  if (isAppDescriptorPath(resolvedPath)) {\n    return loadAppDescriptorConfig(resolvedPath);\n  }\n  return JSON.parse(readFileSync(resolvedPath, \"utf-8\")) as BosConfigInput;\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,eAAe;AAC5B,MAAa,yBAAyB;AAEtC,MAAa,uBAAuB;AAOpC,MAAM,iBAAiB,IAAIA,mCAAoD;;;;;;AAO/E,SAAgB,yBAA4B,MAAgB,IAAgB;CAC1E,OAAO,eAAe,IAAI;EAAE;EAAM,UAAU,eAAe,SAAS;CAAE,GAAG,EAAE;AAC7E;AAEA,SAAgB,kBAAkB,SAAuB;CACvD,MAAM,UAAU,eAAe,SAAS;CACxC,IAAI,SACF,QAAQ,KAAK,KAAK,OAAO;MAEzB,QAAQ,KAAK,OAAO;AAExB;AAEA,MAAM,kCAAkB,IAAI,IAA2B;;;;;AAMvD,SAAgB,uBAA6B;CAC3C,gBAAgB,MAAM;AACxB;;;;;;AAOA,eAAsB,wBAAwB,KAA8C;CAC1F,MAAM,aAAa,eAAe,GAAG;CACrC,IAAI,CAAC,cAAc,WAAW,WAAW,QAAQ,GAAG,OAAO;CAC3D,OAAO,gBAAgB,gBAAYC,mBAAQ,UAAU,CAAC;AACxD;;;;;;;;AASA,SAAgB,qBAAqB,KAA4B;CAC/D,MAAM,cAAUC,gBAAK,KAAK,YAAY;CACtC,QAAIC,oBAAW,OAAO,GAAG,OAAO;CAChC,MAAM,eAAWD,gBAAK,KAAK,iBAAiB;CAC5C,WAAOC,oBAAW,QAAQ,IAAI,WAAW;AAC3C;;AAGA,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