@yk1028-test/ai-chat-supporter
Version:
AI Chat Supporter - TypeScript library for intelligent chat processing with LangChain integration
99 lines • 3.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.globalPersonaManager = exports.PersonaManager = exports.BasePersona = void 0;
// 기본 페르소나 클래스
class BasePersona {
constructor(id, name, description, systemPrompt, tags = [], version = '1.0.0') {
this.id = id;
this.name = name;
this.description = description;
this.systemPrompt = systemPrompt;
this.tags = tags;
this.version = version;
}
// 설정에 따라 시스템 프롬프트를 커스터마이징
getCustomizedPrompt(config) {
let prompt = this.systemPrompt;
if (config?.customInstructions && config.customInstructions.length > 0) {
prompt += '\n\n추가 지침:\n' + config.customInstructions.join('\n');
}
return prompt;
}
// 페르소나가 특정 태그를 가지고 있는지 확인
hasTag(tag) {
return this.tags.includes(tag);
}
// 페르소나 정보를 JSON으로 직렬화
toJSON() {
return {
id: this.id,
name: this.name,
description: this.description,
systemPrompt: this.systemPrompt,
tags: this.tags,
version: this.version,
};
}
}
exports.BasePersona = BasePersona;
// 페르소나 매니저
class PersonaManager {
constructor() {
this.personas = new Map();
this.configs = new Map();
}
// 페르소나 등록
register(persona, config) {
this.personas.set(persona.id, persona);
if (config) {
this.configs.set(persona.id, config);
}
}
// 페르소나 조회
get(id) {
return this.personas.get(id);
}
// 페르소나 설정 조회
getConfig(id) {
return this.configs.get(id);
}
// 페르소나 설정 업데이트
updateConfig(id, config) {
if (this.personas.has(id)) {
this.configs.set(id, { ...this.configs.get(id), ...config });
}
}
// 모든 페르소나 목록 조회
list() {
return Array.from(this.personas.values());
}
// 태그로 페르소나 검색
findByTag(tag) {
return this.list().filter(persona => persona.hasTag && persona.hasTag(tag));
}
// 페르소나 삭제
remove(id) {
const deleted = this.personas.delete(id);
this.configs.delete(id);
return deleted;
}
// 페르소나 존재 확인
exists(id) {
return this.personas.has(id);
}
// 커스터마이징된 시스템 프롬프트 가져오기
getSystemPrompt(id) {
const persona = this.get(id);
if (!persona)
return undefined;
const config = this.getConfig(id);
if (persona instanceof BasePersona) {
return persona.getCustomizedPrompt(config);
}
return persona.systemPrompt;
}
}
exports.PersonaManager = PersonaManager;
// 글로벌 페르소나 매니저 인스턴스
exports.globalPersonaManager = new PersonaManager();
//# sourceMappingURL=base.js.map