package-dependency-policy.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /** Explicit exceptions and Host packages for the published dependency policy. */
  2. /** Packages treated as Client/Host packages without declaring `dsh.client`. */
  3. const CLIENT_FACE_INCLUDE: readonly string[] = []
  4. /** Packages exempted from automatic Client/Host treatment despite declaring `dsh.client`. */
  5. const CLIENT_FACE_EXCLUDE: readonly string[] = [
  6. '@deepseek-ai/dsh-api-session-controller',
  7. '@deepseek-ai/dsh-api-workspace-controller',
  8. ]
  9. /** Host-only packages whose peer relays are deliberately flattened. */
  10. const HOST_DEPENDENCY_PACKAGES: readonly string[] = [
  11. '@deepseek-ai/dsh-llm',
  12. '@deepseek-ai/dsh-session',
  13. ]
  14. /** Development-only package relationships not represented by source imports. */
  15. const CONFIGURATION_ONLY_DEV_DEPENDENCIES = {
  16. '@deepseek-ai/dsh-client-locale': ['@deepseek-ai/dsh-api-remotes'],
  17. '@deepseek-ai/dsh-client-ui-conversation': [
  18. '@deepseek-ai/dsh-api-remotes',
  19. '@deepseek-ai/dsh-client-ui-workspace',
  20. ],
  21. '@deepseek-ai/dsh-client-ui-model-selection': ['@deepseek-ai/dsh-client-ui-input-trigger'],
  22. '@deepseek-ai/dsh-client-ui-sidebar': ['@deepseek-ai/dsh-client-ui-workspace'],
  23. '@deepseek-ai/dsh-client-ui-subagent': ['@deepseek-ai/dsh-client-ui-input-trigger'],
  24. '@deepseek-ai/dsh-client-ui-theme': ['@deepseek-ai/dsh-api-remotes'],
  25. '@deepseek-ai/dsh-client-ui-tool': ['@deepseek-ai/dsh-api-remotes'],
  26. } as const satisfies Readonly<Record<string, readonly string[]>>
  27. /**
  28. * Runtime exports whose values remain valid when npm installs another package copy.
  29. */
  30. const SAFE_HOST_DEPENDENCY_EXPORTS = {
  31. '@deepseek-ai/dsh-api-session-controller/remote-events': ['SESSION_CONTROLLER_REMOTE_EVENTS'],
  32. '@deepseek-ai/dsh-credentials': ['credentialKey'],
  33. '@deepseek-ai/dsh-llm': ['MessageId', 'callConfigEquals', 'deepFreeze', 'freezeMessage'],
  34. '@deepseek-ai/dsh-llm/brand': ['ToolCallId'],
  35. '@deepseek-ai/dsh-session': ['isJsonValue'],
  36. '@deepseek-ai/dsh-session/types': ['SessionId'],
  37. '@deepseek-ai/dsh-settings': ['settingsNamespace'],
  38. '@deepseek-ai/dsh-system-prompt': ['FIRST_PARTY_SECTION_ORDER'],
  39. '@deepseek-ai/dsh-timeout': ['MAX_TIMER_DELAY_MS'],
  40. '@deepseek-ai/dsh-typert-protocol': ['RemoteError', 'remoteErrorOf'],
  41. '@deepseek-ai/dsh-util-crypto': ['randomUUID'],
  42. '@deepseek-ai/schemastery': ['default'],
  43. } as const satisfies HostDependencyExports
  44. /** Runtime exports that require every consumer to resolve the provider's shared peer instance. */
  45. const PEER_REQUIRED_HOST_EXPORTS = {
  46. '@deepseek-ai/dsh-scope': ['carrierKeyOf', 'scopeOf', 'scopeTarget'],
  47. '@deepseek-ai/dsh-typert-protocol': ['Remote', 'TypertRemoteService', 'remoteMethods'],
  48. } as const satisfies HostDependencyExports
  49. /** Exact import specifier to reviewed runtime exports. */
  50. type HostDependencyExports = Readonly<Record<string, readonly string[]>>
  51. /** Complete configurable input to package dependency classification. */
  52. export interface PackageDependencyPolicy {
  53. readonly clientFaceInclude: readonly string[]
  54. readonly clientFaceExclude: readonly string[]
  55. readonly hostPackages: readonly string[]
  56. readonly configurationOnlyDevDependencies: Readonly<Record<string, readonly string[]>>
  57. readonly safeHostDependencyExports: HostDependencyExports
  58. readonly peerRequiredHostExports: HostDependencyExports
  59. }
  60. /** Repository dependency policy consumed by verification and benchmarking. */
  61. export const PACKAGE_DEPENDENCY_POLICY: PackageDependencyPolicy = {
  62. clientFaceInclude: CLIENT_FACE_INCLUDE,
  63. clientFaceExclude: CLIENT_FACE_EXCLUDE,
  64. hostPackages: HOST_DEPENDENCY_PACKAGES,
  65. configurationOnlyDevDependencies: CONFIGURATION_ONLY_DEV_DEPENDENCIES,
  66. safeHostDependencyExports: SAFE_HOST_DEPENDENCY_EXPORTS,
  67. peerRequiredHostExports: PEER_REQUIRED_HOST_EXPORTS,
  68. }
  69. function isRecord(value: unknown): value is Record<string, unknown> {
  70. return typeof value === 'object' && value !== null && !Array.isArray(value)
  71. }
  72. /** Whether a package manifest declares a dynamically loaded Client entry. */
  73. export function hasClientDeclaration(dshField: unknown): boolean {
  74. return isRecord(dshField) && Object.hasOwn(dshField, 'client')
  75. }
  76. /** Whether the repository policy flattens one package's non-Cordis peers. */
  77. export function usesFlattenedPackageDependencies(
  78. manifestPath: string,
  79. packageName: string,
  80. dshField: unknown,
  81. policy: PackageDependencyPolicy = PACKAGE_DEPENDENCY_POLICY,
  82. ): boolean {
  83. if (!manifestPath.startsWith('packages/') || manifestPath.startsWith('packages/experimental/')) return false
  84. if (policy.hostPackages.includes(packageName)) return true
  85. if (manifestPath.startsWith('packages/client/')) return true
  86. const included = hasClientDeclaration(dshField) || policy.clientFaceInclude.includes(packageName)
  87. return included && !policy.clientFaceExclude.includes(packageName)
  88. }