41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import type { CreatedPartnerSubagent } from '@/stores/partner-profiles';
|
|
|
|
function createLocalSubagentId(): string {
|
|
const timestamp = new Date().toISOString().replace(/\D/g, '').slice(0, 14);
|
|
const randomPart = typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
|
|
? crypto.randomUUID().replace(/-/g, '').slice(0, 6)
|
|
: Math.random().toString(16).slice(2, 8).padEnd(6, '0');
|
|
return `makelore-custom-${timestamp}-${randomPart}`;
|
|
}
|
|
|
|
export function getSubagentManualSkillIds(subagent: CreatedPartnerSubagent): string[] {
|
|
return [...new Set((subagent.skillIds ?? []).map((skillId) => skillId.trim()).filter(Boolean))];
|
|
}
|
|
|
|
export function getSubagentRuntimeSkillIds(subagent: CreatedPartnerSubagent): string[] {
|
|
return getSubagentManualSkillIds(subagent);
|
|
}
|
|
|
|
export function hasAllSkillIds(actualSkillIds: readonly string[] | undefined, requiredSkillIds: readonly string[]): boolean {
|
|
const actual = new Set(actualSkillIds ?? []);
|
|
return requiredSkillIds.every((skillId) => actual.has(skillId));
|
|
}
|
|
|
|
export function createLocalPartnerSubagent(input: {
|
|
displayName: string;
|
|
prompt?: string;
|
|
skillIds?: string[];
|
|
}): CreatedPartnerSubagent {
|
|
const now = new Date().toISOString();
|
|
const prompt = input.prompt?.trim();
|
|
return {
|
|
id: createLocalSubagentId(),
|
|
displayName: input.displayName.trim(),
|
|
templateRoleId: 'custom',
|
|
skillIds: [...new Set((input.skillIds ?? []).map((skillId) => skillId.trim()).filter(Boolean))],
|
|
...(prompt ? { prompt } : {}),
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
};
|
|
}
|