fetchSkill method
Fetch skill from GitHub repository
repo Repository in format 'owner/repo'
skillName Name of the skill to fetch
branch Git branch to fetch from (default: 'main')
Implementation
Future<Skill> fetchSkill(
String repo,
String skillName, {
String branch = 'main',
}) async {
final cacheKey = '$repo-$branch-$skillName';
// Try loading from cache first
final cached = await _loadFromCache(cacheKey);
if (cached != null) {
return cached;
}
// Fetch from GitHub
final url = Uri.parse(
'$githubRawUrl/$repo/$branch/.ai/skills/$skillName/SKILL.md.mustache',
);
final response = await client.get(url);
if (response.statusCode != 200) {
throw SkillLoadException(
'Failed to fetch skill: HTTP ${response.statusCode}',
url.toString(),
);
}
final content = response.body;
// Cache the skill content
await _saveToCache(cacheKey, content);
// Try to fetch metadata
final metaUrl = Uri.parse(
'$githubRawUrl/$repo/$branch/.ai/skills/$skillName/meta.yaml',
);
SkillMetadata metadata;
try {
final metaResponse = await client.get(metaUrl);
if (metaResponse.statusCode == 200) {
metadata = _parseMetadata(metaResponse.body);
} else {
metadata = SkillMetadata.defaults;
}
} catch (e) {
metadata = SkillMetadata.defaults;
}
return Skill(
name: skillName,
description: metadata.description,
template: content,
metadata: metadata.copyWith(source: SkillSource.github(repo)),
);
}