收口 Makelore 客户端变更
This commit is contained in:
@@ -31,6 +31,21 @@ function normalizeProjectType(value: unknown): ProjectType {
|
||||
throw new Error('Invalid project type');
|
||||
}
|
||||
|
||||
function needsLegacyAgentModelMigration(value: unknown): boolean {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
||||
const raw = value as Partial<ProjectConfig>;
|
||||
const defaultModel = typeof raw.defaultModel === 'string' && raw.defaultModel.trim()
|
||||
? raw.defaultModel.trim()
|
||||
: null;
|
||||
if (!defaultModel || !Array.isArray(raw.agents)) return false;
|
||||
return raw.agents.some((agent) => (
|
||||
Boolean(agent)
|
||||
&& typeof agent === 'object'
|
||||
&& !(typeof (agent as { model?: unknown }).model === 'string'
|
||||
&& (agent as { model?: string }).model?.trim())
|
||||
));
|
||||
}
|
||||
|
||||
function normalizeAgent(value: unknown): ProjectAgentConfig | null {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
||||
const raw = value as Partial<ProjectAgentConfig>;
|
||||
@@ -80,9 +95,16 @@ export function normalizeProjectConfig(value: unknown): ProjectConfig {
|
||||
}
|
||||
const raw = value as Partial<ProjectConfig>;
|
||||
if (raw.schemaVersion !== 1) throw new Error('Unsupported project config schema');
|
||||
const defaultModel = typeof raw.defaultModel === 'string' && raw.defaultModel.trim()
|
||||
? raw.defaultModel.trim()
|
||||
: null;
|
||||
const agents = Array.isArray(raw.agents) ? raw.agents.map(normalizeAgent) : [];
|
||||
if (agents.some((item) => !item)) throw new Error('Invalid project Agent configuration');
|
||||
const normalizedAgents = agents.filter((item): item is ProjectAgentConfig => Boolean(item));
|
||||
const normalizedAgents = agents
|
||||
.filter((item): item is ProjectAgentConfig => Boolean(item))
|
||||
.map((agent) => agent.model || !defaultModel
|
||||
? agent
|
||||
: { ...agent, model: defaultModel });
|
||||
if (new Set(normalizedAgents.map((item) => item.id)).size !== normalizedAgents.length) {
|
||||
throw new Error('Duplicate project Agent id');
|
||||
}
|
||||
@@ -97,10 +119,9 @@ export function normalizeProjectConfig(value: unknown): ProjectConfig {
|
||||
schemaVersion: 1,
|
||||
projectType: normalizeProjectType(raw.projectType),
|
||||
initialized,
|
||||
superpowersEnabled: raw.superpowersEnabled === true,
|
||||
defaultModel: typeof raw.defaultModel === 'string' && raw.defaultModel.trim()
|
||||
? raw.defaultModel.trim()
|
||||
: null,
|
||||
// Keep this legacy field readable for compatibility, but runtime model
|
||||
// selection is owned by each project Agent.
|
||||
defaultModel,
|
||||
agents: normalizedAgents,
|
||||
knowledgeDirectory: 'knowledge',
|
||||
createdAt,
|
||||
@@ -111,7 +132,12 @@ export function normalizeProjectConfig(value: unknown): ProjectConfig {
|
||||
export async function readProjectConfig(projectPath: string): Promise<ProjectConfigReadResult> {
|
||||
try {
|
||||
const raw = JSON.parse(await readFile(configPath(projectPath), 'utf8')) as unknown;
|
||||
return { status: 'valid', config: normalizeProjectConfig(raw) };
|
||||
const config = normalizeProjectConfig(raw);
|
||||
if (needsLegacyAgentModelMigration(raw)) {
|
||||
if (config.initialized) await materializeAgents(projectPath, config);
|
||||
await writeFile(configPath(projectPath), `${JSON.stringify(config, null, 2)}\n`, 'utf8');
|
||||
}
|
||||
return { status: 'valid', config };
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return { status: 'missing' };
|
||||
return { status: 'invalid', error: error instanceof Error ? error.message : String(error) };
|
||||
@@ -165,7 +191,7 @@ function buildAgentMarkdown(config: ProjectConfig, agent: ProjectAgentConfig): s
|
||||
? agent.skillIds.map((skill) => ` ${skill}: allow`).join('\n')
|
||||
: ' "*": deny';
|
||||
const shellPermission = agent.skillIds.includes('game-assets') ? ' bash: allow\n' : '';
|
||||
const model = agent.model ?? config.defaultModel;
|
||||
const model = agent.model;
|
||||
const prompt = agent.prompt.trim() || buildProjectAgentPrompt(config, agent);
|
||||
return `---
|
||||
description: ${yamlString(agent.name)}
|
||||
|
||||
Reference in New Issue
Block a user