@42ailab/42plugin 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/db.ts +28 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "活水插件",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/db.ts CHANGED
@@ -467,7 +467,8 @@ export async function downloadAndExtract(
467
467
  url: string,
468
468
  expectedChecksum: string,
469
469
  fullName: string,
470
- version: string
470
+ version: string,
471
+ pluginType: string
471
472
  ): Promise<string> {
472
473
  const parts = fullName.split('/');
473
474
  const targetDir = path.join(config.cacheDir, ...parts, version);
@@ -550,7 +551,7 @@ export async function downloadAndExtract(
550
551
  await fs.unlink(tempFile).catch(() => {});
551
552
 
552
553
  // 返回最终路径(如果只有一个子目录则进入)
553
- return resolveFinalPath(targetDir);
554
+ return resolveFinalPath(targetDir, pluginType);
554
555
  } catch (error) {
555
556
  await fs.rm(targetDir, { recursive: true, force: true }).catch(() => {});
556
557
  throw error;
@@ -559,8 +560,9 @@ export async function downloadAndExtract(
559
560
 
560
561
  /**
561
562
  * 修正旧缓存路径(如果是目录但应该是文件)
563
+ * @param pluginType 插件类型:skill 需要目录,agent/command 需要文件
562
564
  */
563
- async function correctCachePath(cachePath: string): Promise<string> {
565
+ async function correctCachePath(cachePath: string, pluginType: string): Promise<string> {
564
566
  try {
565
567
  const stat = await fs.stat(cachePath);
566
568
  if (!stat.isDirectory()) {
@@ -577,11 +579,16 @@ async function correctCachePath(cachePath: string): Promise<string> {
577
579
  // 如果只有一个子目录(且没有其他文件),递归进入
578
580
  if (dirs.length === 1 && nonMetadataFiles.length === 0) {
579
581
  const subDir = path.join(cachePath, dirs[0].name);
580
- return correctCachePath(subDir);
582
+ return correctCachePath(subDir, pluginType);
581
583
  }
582
584
 
583
- // 如果只有一个主文件(排除 metadata.json),返回该文件路径
585
+ // Skill 类型:保持目录结构(包含 SKILL.md)
586
+ // Agent/Command 类型:返回 .md 文件路径
584
587
  if (nonMetadataFiles.length === 1 && dirs.length === 0) {
588
+ if (pluginType === 'skill') {
589
+ // Skill 需要目录,不返回文件
590
+ return cachePath;
591
+ }
585
592
  return path.join(cachePath, nonMetadataFiles[0].name);
586
593
  }
587
594
 
@@ -591,7 +598,11 @@ async function correctCachePath(cachePath: string): Promise<string> {
591
598
  }
592
599
  }
593
600
 
594
- async function resolveFinalPath(dir: string): Promise<string> {
601
+ /**
602
+ * 解析最终路径
603
+ * @param pluginType 插件类型:skill 需要目录,agent/command 需要文件
604
+ */
605
+ async function resolveFinalPath(dir: string, pluginType: string): Promise<string> {
595
606
  const entries = await fs.readdir(dir, { withFileTypes: true });
596
607
  const dirs = entries.filter((e) => e.isDirectory() && !e.name.startsWith('.'));
597
608
  const files = entries.filter((e) => e.isFile() && !e.name.startsWith('.'));
@@ -603,13 +614,17 @@ async function resolveFinalPath(dir: string): Promise<string> {
603
614
  const subEntries = await fs.readdir(subDir);
604
615
  if (subEntries.length > 0) {
605
616
  // 递归查找,处理 agent/command 类型的 name/name.md 结构
606
- return resolveFinalPath(subDir);
617
+ return resolveFinalPath(subDir, pluginType);
607
618
  }
608
619
  }
609
620
 
610
- // 如果只有一个主文件(排除 metadata.json),返回该文件路径
611
- // 这是单文件插件(如 agent/command)的情况
621
+ // Skill 类型:保持目录结构(包含 SKILL.md)
622
+ // Agent/Command 类型:返回 .md 文件路径
612
623
  if (nonMetadataFiles.length === 1 && dirs.length === 0) {
624
+ if (pluginType === 'skill') {
625
+ // Skill 需要目录,不返回文件
626
+ return dir;
627
+ }
613
628
  return path.join(dir, nonMetadataFiles[0].name);
614
629
  }
615
630
 
@@ -701,8 +716,8 @@ export async function resolveCachePath(
701
716
  // 验证缓存文件是否仍然存在
702
717
  try {
703
718
  await fs.access(cached.cachePath);
704
- // 修正旧缓存的路径(可能是目录而应该是文件)
705
- const correctedPath = await correctCachePath(cached.cachePath);
719
+ // 修正旧缓存的路径(根据类型:skill 需要目录,agent/command 需要文件)
720
+ const correctedPath = await correctCachePath(cached.cachePath, downloadInfo.type);
706
721
  // 如果路径被修正,更新缓存记录
707
722
  if (correctedPath !== cached.cachePath) {
708
723
  await setCache({
@@ -726,7 +741,8 @@ export async function resolveCachePath(
726
741
  downloadInfo.downloadUrl,
727
742
  downloadInfo.checksum,
728
743
  downloadInfo.fullName,
729
- downloadInfo.version
744
+ downloadInfo.version,
745
+ downloadInfo.type
730
746
  );
731
747
 
732
748
  // 更新缓存记录