mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-24 19:35:44 +08:00
fix(skills): overwrite existing installations
Replace an existing skill directory instead of rejecting a duplicate installation. Remove stale supporting files so the installed directory exactly matches the new upload.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import path from 'node:path';
|
||||
import { mkdir, stat, writeFile } from 'node:fs/promises';
|
||||
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
||||
|
||||
import type { IProviderSkills } from '@/shared/interfaces.js';
|
||||
import type {
|
||||
@@ -44,19 +44,6 @@ type PendingSkillInstall = {
|
||||
skill: ProviderSkill;
|
||||
};
|
||||
|
||||
const pathExists = async (targetPath: string): Promise<boolean> => {
|
||||
try {
|
||||
await stat(targetPath);
|
||||
return true;
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const resolveSkillSupportingFilePath = (
|
||||
skillDirectoryPath: string,
|
||||
relativePath: string,
|
||||
@@ -196,13 +183,6 @@ export abstract class SkillsProvider implements IProviderSkills {
|
||||
}
|
||||
|
||||
seenSkillPaths.add(normalizedSkillPath);
|
||||
if (await pathExists(skillDirectoryPath)) {
|
||||
throw new AppError(`Skill target "${resolvedDirectoryName}" already exists.`, {
|
||||
code: 'PROVIDER_SKILL_ALREADY_EXISTS',
|
||||
statusCode: 409,
|
||||
});
|
||||
}
|
||||
|
||||
const supportingFiles = (entry.files ?? []).map((file) => ({
|
||||
targetPath: resolveSkillSupportingFilePath(skillDirectoryPath, file.relativePath, index),
|
||||
content: file.encoding === 'base64'
|
||||
@@ -243,6 +223,8 @@ export abstract class SkillsProvider implements IProviderSkills {
|
||||
}
|
||||
|
||||
for (const install of pendingInstalls) {
|
||||
// Replace the complete skill directory so removed scripts or assets do not remain stale.
|
||||
await rm(install.skillDirectoryPath, { recursive: true, force: true });
|
||||
await mkdir(install.skillDirectoryPath, { recursive: true });
|
||||
await writeFile(install.skillPath, `${install.content}\n`, 'utf8');
|
||||
for (const file of install.supportingFiles) {
|
||||
|
||||
Reference in New Issue
Block a user