2026-03-20 08:17:34 +08:00
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
import 'aris_bundle.dart';
|
|
|
|
|
|
import 'runtime_models.dart';
|
|
|
|
|
|
|
|
|
|
|
|
abstract class FrameworkPreset {
|
|
|
|
|
|
const FrameworkPreset();
|
|
|
|
|
|
|
|
|
|
|
|
String get id;
|
|
|
|
|
|
String get label;
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> roleInstructionBlock({
|
|
|
|
|
|
required MultiAgentRole role,
|
|
|
|
|
|
required String tool,
|
|
|
|
|
|
required List<String> selectedSkills,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class NativeFrameworkPreset extends FrameworkPreset {
|
|
|
|
|
|
const NativeFrameworkPreset();
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String get id => MultiAgentFramework.native.name;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String get label => MultiAgentFramework.native.label;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Future<String> roleInstructionBlock({
|
|
|
|
|
|
required MultiAgentRole role,
|
|
|
|
|
|
required String tool,
|
|
|
|
|
|
required List<String> selectedSkills,
|
|
|
|
|
|
}) async {
|
|
|
|
|
|
final selected = selectedSkills.isEmpty
|
|
|
|
|
|
? '- 无'
|
|
|
|
|
|
: selectedSkills.map((item) => '- $item').join('\n');
|
|
|
|
|
|
return '''
|
|
|
|
|
|
当前协作框架:$label
|
|
|
|
|
|
当前角色:${role.label}
|
|
|
|
|
|
当前工具:$tool
|
|
|
|
|
|
|
|
|
|
|
|
用户当前选中的技能:
|
|
|
|
|
|
$selected
|
|
|
|
|
|
''';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ArisFrameworkPreset extends FrameworkPreset {
|
2026-03-28 17:06:52 +08:00
|
|
|
|
ArisFrameworkPreset(this.bundleRepositoryInternal);
|
2026-03-20 08:17:34 +08:00
|
|
|
|
|
2026-03-28 17:06:52 +08:00
|
|
|
|
final ArisBundleRepository bundleRepositoryInternal;
|
2026-03-20 08:17:34 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String get id => MultiAgentFramework.aris.name;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String get label => MultiAgentFramework.aris.label;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Future<String> roleInstructionBlock({
|
|
|
|
|
|
required MultiAgentRole role,
|
|
|
|
|
|
required String tool,
|
|
|
|
|
|
required List<String> selectedSkills,
|
|
|
|
|
|
}) async {
|
2026-03-28 17:06:52 +08:00
|
|
|
|
final bundle = await bundleRepositoryInternal.ensureReady();
|
2026-03-20 08:17:34 +08:00
|
|
|
|
final preferCodex = tool.trim().toLowerCase() == 'codex';
|
|
|
|
|
|
final skillPaths = bundle.skillPathsForRole(role, preferCodex: preferCodex);
|
2026-03-28 17:06:52 +08:00
|
|
|
|
final skillDocs = await bundleRepositoryInternal.loadSkillContents(
|
|
|
|
|
|
skillPaths,
|
|
|
|
|
|
);
|
2026-03-20 08:17:34 +08:00
|
|
|
|
final selected = selectedSkills.isEmpty
|
|
|
|
|
|
? '- 无'
|
|
|
|
|
|
: selectedSkills.map((item) => '- $item').join('\n');
|
|
|
|
|
|
final excerpts = skillDocs.entries
|
|
|
|
|
|
.map(
|
2026-03-28 17:06:52 +08:00
|
|
|
|
(entry) =>
|
|
|
|
|
|
formatSkillExcerptInternal(path: entry.key, content: entry.value),
|
2026-03-20 08:17:34 +08:00
|
|
|
|
)
|
|
|
|
|
|
.join('\n\n');
|
|
|
|
|
|
return '''
|
|
|
|
|
|
当前协作框架:$label
|
|
|
|
|
|
当前角色:${role.label}
|
|
|
|
|
|
当前工具:$tool
|
|
|
|
|
|
ARIS bundle:${bundle.manifest.bundleVersion}
|
|
|
|
|
|
|
|
|
|
|
|
用户当前选中的技能:
|
|
|
|
|
|
$selected
|
|
|
|
|
|
|
|
|
|
|
|
请优先遵循以下内嵌 ARIS 技能方法:
|
|
|
|
|
|
$excerpts
|
|
|
|
|
|
''';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-28 17:06:52 +08:00
|
|
|
|
String formatSkillExcerptInternal({
|
2026-03-20 08:17:34 +08:00
|
|
|
|
required String path,
|
|
|
|
|
|
required String content,
|
|
|
|
|
|
}) {
|
2026-03-28 17:06:52 +08:00
|
|
|
|
final label = File(
|
|
|
|
|
|
path,
|
|
|
|
|
|
).parent.uri.pathSegments.where((item) => item.isNotEmpty).last;
|
2026-03-20 08:17:34 +08:00
|
|
|
|
final lines = content
|
|
|
|
|
|
.split('\n')
|
|
|
|
|
|
.map((line) => line.trimRight())
|
|
|
|
|
|
.where((line) => line.isNotEmpty)
|
|
|
|
|
|
.take(60)
|
|
|
|
|
|
.join('\n');
|
|
|
|
|
|
return '''
|
|
|
|
|
|
## $label
|
|
|
|
|
|
来源:$path
|
|
|
|
|
|
$lines
|
|
|
|
|
|
''';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|