local-runtime-assets.mjs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { cpSync, existsSync, rmSync } from 'node:fs';
  2. import path from 'node:path';
  3. /**
  4. * Copies shared local-runtime assets and the canonical V2 Agent asset tree.
  5. * Agent definitions/prompts have one source of truth under local-runtime-v2;
  6. * the V1 package no longer ships a second builtin Agent tree.
  7. */
  8. export function copyLocalRuntimeAssets({
  9. repositoryRoot,
  10. outputDir,
  11. filter,
  12. excludedBuiltinSkillNames = [],
  13. }) {
  14. const assetsSrc = path.join(repositoryRoot, 'packages/local-runtime/assets');
  15. const v2AgentAssetsSrc = path.join(repositoryRoot, 'packages/local-runtime-v2/assets/agents');
  16. const v2ProviderCatalogSrc = path.join(
  17. repositoryRoot,
  18. 'packages/local-runtime-v2/assets/models-dev-catalog.json.gz',
  19. );
  20. const assetsDst = path.join(outputDir, 'assets');
  21. const v2AgentAssetsDst = path.join(assetsDst, 'agents');
  22. const v2ProviderCatalogDst = path.join(assetsDst, 'models-dev-catalog.json.gz');
  23. const excludedBuiltinSkills = new Set(excludedBuiltinSkillNames);
  24. const isExcludedBuiltinSkill = (sourcePath) =>
  25. path.basename(path.dirname(sourcePath)) === 'skills' &&
  26. excludedBuiltinSkills.has(path.basename(sourcePath));
  27. const shouldCopyFrom = (sourceRoot, sourcePath) => filter(path.relative(sourceRoot, sourcePath));
  28. if (!existsSync(assetsSrc)) {
  29. throw new Error('packages/local-runtime/assets not found');
  30. }
  31. if (!existsSync(v2AgentAssetsSrc)) {
  32. throw new Error('packages/local-runtime-v2/assets/agents not found');
  33. }
  34. if (!existsSync(v2ProviderCatalogSrc)) {
  35. throw new Error('packages/local-runtime-v2/assets/models-dev-catalog.json.gz not found');
  36. }
  37. rmSync(assetsDst, { recursive: true, force: true });
  38. cpSync(assetsSrc, assetsDst, {
  39. recursive: true,
  40. filter: (sourcePath) => {
  41. // The canonical Agent tree is copied below from V2. Do not resurrect
  42. // a duplicate packages/local-runtime/assets/agents source tree.
  43. return (
  44. sourcePath !== path.join(assetsSrc, 'agents') &&
  45. !isExcludedBuiltinSkill(sourcePath) &&
  46. shouldCopyFrom(assetsSrc, sourcePath)
  47. );
  48. },
  49. });
  50. cpSync(v2AgentAssetsSrc, v2AgentAssetsDst, {
  51. recursive: true,
  52. filter: (sourcePath) =>
  53. !isExcludedBuiltinSkill(sourcePath) && shouldCopyFrom(v2AgentAssetsSrc, sourcePath),
  54. });
  55. cpSync(v2ProviderCatalogSrc, v2ProviderCatalogDst);
  56. }