feat(agent): add profile name and user content management
Add methods to ProfileManager, Agent, and AsyncAgent for: - Getting/setting agent display name (stored in config.json) - Getting/setting user.md content This enables the desktop app to manage agent settings. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e9ed53b615
commit
a80c858ce5
4 changed files with 95 additions and 0 deletions
|
|
@ -148,4 +148,32 @@ export class AsyncAgent {
|
|||
getProfileId(): string | undefined {
|
||||
return this.agent.getProfileId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agent display name from profile config.
|
||||
*/
|
||||
getAgentName(): string | undefined {
|
||||
return this.agent.getAgentName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update agent display name in profile config.
|
||||
*/
|
||||
setAgentName(name: string): void {
|
||||
this.agent.setAgentName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user.md content from profile.
|
||||
*/
|
||||
getUserContent(): string | undefined {
|
||||
return this.agent.getUserContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user.md content in profile.
|
||||
*/
|
||||
setUserContent(content: string): void {
|
||||
this.agent.setUserContent(content);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@ import {
|
|||
loadProfile,
|
||||
profileExists,
|
||||
saveProfile,
|
||||
writeProfileConfig,
|
||||
writeProfileFile,
|
||||
} from "./storage.js";
|
||||
import { PROFILE_FILES } from "./types.js";
|
||||
|
||||
export { type AgentProfile, type CreateProfileOptions, type ProfileConfig, type ProfileManagerOptions } from "./types.js";
|
||||
export { DEFAULT_TEMPLATES } from "./templates.js";
|
||||
|
|
@ -215,4 +218,38 @@ export class ProfileManager {
|
|||
this.updateToolsConfig(newConfig);
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
/** 获取 Agent 名称 */
|
||||
getName(): string | undefined {
|
||||
const profile = this.getProfile();
|
||||
return profile?.config?.name;
|
||||
}
|
||||
|
||||
/** 更新 Agent 名称 */
|
||||
updateName(name: string): void {
|
||||
const profile = this.getOrCreateProfile(false);
|
||||
const currentConfig = profile.config ?? {};
|
||||
const newConfig: ProfileConfig = {
|
||||
...currentConfig,
|
||||
name,
|
||||
};
|
||||
profile.config = newConfig;
|
||||
this.profile = profile;
|
||||
writeProfileConfig(this.profileId, newConfig, { baseDir: this.baseDir });
|
||||
}
|
||||
|
||||
/** 获取 user.md 内容 */
|
||||
getUserContent(): string | undefined {
|
||||
const profile = this.getProfile();
|
||||
return profile?.user;
|
||||
}
|
||||
|
||||
/** 更新 user.md 内容 */
|
||||
updateUserContent(content: string): void {
|
||||
writeProfileFile(this.profileId, PROFILE_FILES.user, content, { baseDir: this.baseDir });
|
||||
// Update cached profile
|
||||
if (this.profile) {
|
||||
this.profile.user = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ export const PROFILE_FILES = {
|
|||
|
||||
/** Profile config.json structure */
|
||||
export interface ProfileConfig {
|
||||
/** Agent display name */
|
||||
name?: string;
|
||||
/** Tools policy configuration */
|
||||
tools?: ToolsConfig;
|
||||
/** Default LLM provider */
|
||||
|
|
|
|||
|
|
@ -532,4 +532,32 @@ export class Agent {
|
|||
getProfileId(): string | undefined {
|
||||
return this.profile?.getProfile()?.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agent display name from profile config.
|
||||
*/
|
||||
getAgentName(): string | undefined {
|
||||
return this.profile?.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update agent display name in profile config.
|
||||
*/
|
||||
setAgentName(name: string): void {
|
||||
this.profile?.updateName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user.md content from profile.
|
||||
*/
|
||||
getUserContent(): string | undefined {
|
||||
return this.profile?.getUserContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user.md content in profile.
|
||||
*/
|
||||
setUserContent(content: string): void {
|
||||
this.profile?.updateUserContent(content);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue