163 lines
9.4 KiB
JavaScript
163 lines
9.4 KiB
JavaScript
/**
|
||
* AI Logic Module
|
||
* Simulates intelligent healing responses and content generation.
|
||
*/
|
||
|
||
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||
|
||
const ADJECTIVES = {
|
||
INTJ: ['深刻', '逻辑严密', '富有远见'],
|
||
INFP: ['温柔', '富有同理心', '充满想象力'],
|
||
ENFP: ['热情', '鼓舞人心', '充满可能性'],
|
||
ISTJ: ['稳重', '务实', '值得信赖'],
|
||
INFJ: ['深邃', '直觉敏锐', '利他'],
|
||
|
||
DEFAULT: ['特别', '真诚', '有力量']
|
||
};
|
||
|
||
export const AI = {
|
||
/**
|
||
* Generate a healing reply for a timeline log.
|
||
* Analyzes sentiment and provides Analysis, Growth, and Healing.
|
||
*/
|
||
async generateReply(content, profile) {
|
||
await sleep(1500 + Math.random() * 1000); // Simulate 1.5-2.5s thinking
|
||
|
||
const mbti = profile.mbti || 'DEFAULT';
|
||
const traits = ADJECTIVES[mbti] || ADJECTIVES.DEFAULT;
|
||
const trait = traits[Math.floor(Math.random() * traits.length)];
|
||
const zodiac = profile.zodiac || '星辰';
|
||
|
||
|
||
let mood = 'neutral';
|
||
if (/(开心|成功|棒|好|爱|幸福|顺利)/.test(content)) mood = 'positive';
|
||
if (/(难过|累|失败|痛|丧|焦虑|迷茫)/.test(content)) mood = 'negative';
|
||
|
||
let analysis = "";
|
||
let growth = "";
|
||
let healing = "";
|
||
|
||
if (mood === 'positive') {
|
||
analysis = `这不仅仅是一个事件,而是你内心能量充盈的体现。作为${mbti},你敏锐地捕捉到了生活中的光亮。`;
|
||
growth = `请记住这种${trait}的感觉,它构成了你人格中坚韧的底色。你的每一次喜悦,都在为未来的挑战积蓄心理资本。`;
|
||
healing = `愿这一刻的温暖,像${zodiac}的光芒一样,长久地照耀你的内心。`;
|
||
} else if (mood === 'negative') {
|
||
analysis = `感到低落并非示弱,而是灵魂在提醒你需要休息。${mbti}的你往往思考得很深,容易承担过多情绪。`;
|
||
growth = `每一次的阵痛都是成长的伏笔。你正在经历破茧成蝶前的静默,这本身就是一种力量。`;
|
||
healing = `允许自己暂停,就像月亮也有阴晴圆缺。给那个受伤的自己一个拥抱,风雨之后,必见彩虹。`;
|
||
} else {
|
||
analysis = `记录本身就是一种深刻的觉察。你在平淡的流年中,依然保持着${trait}的观察力。`;
|
||
growth = `生活的大部分时间是平静的,能在其中找到节奏,是你最宝贵的能力。`;
|
||
healing = `在这漫长的岁月里,你就是自己最忠实的见证者。`;
|
||
}
|
||
|
||
return {
|
||
analysis,
|
||
growth,
|
||
healing
|
||
};
|
||
},
|
||
|
||
/**
|
||
* Generate a "Cool Story" (爽文) script.
|
||
* Uses profile history (Valley/Peak) to create a narrative arc.
|
||
*/
|
||
async generateScript(profile, timeline, requirements) {
|
||
await sleep(2000 + Math.random() * 1000);
|
||
|
||
const id = Date.now().toString();
|
||
const hobby = (profile.hobbies && profile.hobbies.length > 0) ? profile.hobbies[0] : "隐藏的天赋";
|
||
const theme = requirements.theme || "自我超越";
|
||
|
||
|
||
const valleyEvent = profile.history?.valley?.content
|
||
? `那段"${profile.history.valley.content.substring(0, 15)}..."的经历`
|
||
: "曾经那段默默无闻的时光";
|
||
|
||
const peakEvent = profile.history?.peak?.content
|
||
? `就像"${profile.history.peak.content.substring(0, 15)}..."那次一样`
|
||
: "如同星辰觉醒";
|
||
|
||
const templates = {
|
||
career: {
|
||
intro: `故事始于${valleyEvent}。${profile.nickname}虽然身处低谷,但作为${profile.mbti},${profile.gender === 'male' ? '他' : '她'}内心深处对"${theme}"的渴望从未熄灭。${profile.zodiac}骨子里的韧性,支撑着${profile.gender === 'male' ? '他' : '她'}熬过了最黑的夜。`,
|
||
turning: `转折发生在一个不起眼的午后。公司面临前所未有的技术难题,所有人束手无策。${profile.nickname}利用业余时间钻研的${hobby},意外发现了破局的关键。`,
|
||
explosion: `在项目汇报会上,${profile.nickname}条理清晰地展示了方案,那种自信${peakEvent}。原本轻视的人都闭上了嘴。不仅完美解决了危机,更直接为公司带来了巨大的收益,一战成名!`,
|
||
ending: `最终,${profile.nickname}站在了行业的顶峰,实现了"${theme}"的宏愿。回首往事,轻舟已过万重山,${profile.gender === 'male' ? '他' : '她'}终于成为了自己想成为的人。`
|
||
},
|
||
love: {
|
||
intro: `在${valleyEvent}的日子里,${profile.nickname}习惯了独自一人。${profile.mbti}的特质让${profile.gender === 'male' ? '他' : '她'}虽然渴望爱,却更害怕受伤。`,
|
||
turning: `直到那次${hobby}社团的聚会,命运的齿轮开始转动。${profile.nickname}不经意间流露出的${ADJECTIVES[profile.mbti]?.[0] || '独特'}气质,深深吸引了那个命中注定的人。`,
|
||
explosion: `面对现实的阻碍和误解,${profile.nickname}没有退缩。${profile.zodiac}赋予的勇气觉醒,${profile.gender === 'male' ? '他' : '她'}坚定地跨越了山海,只为奔赴那份真挚的感情。那一刻,全世界都在为爱让路。`,
|
||
ending: `正如${profile.futureVision || '童话故事'}里的结局,两人在夕阳下相拥。${profile.nickname}发现,原来最好的爱,是让你成为更好的自己。`
|
||
},
|
||
fantasy: {
|
||
intro: `在这个看似平凡的世界,${profile.nickname}总感觉自己格格不入。${valleyEvent},其实是灵力觉醒前的阵痛。${profile.zodiac}星盘早已预示了不凡的命运。`,
|
||
turning: `当${hobby}这一媒介触碰到古老的法阵,封印解除!${profile.nickname}发现自己竟然是百年难遇的${profile.mbti}系元素掌控者。`,
|
||
explosion: `暗黑势力降临城市,绝望蔓延。关键时刻,${profile.nickname}挺身而出,爆发出了${peakEvent}般耀眼的光芒,一击必杀,守护了心中的"${theme}"。`,
|
||
ending: `成为了传说中的守护神,${profile.nickname}站在云端俯瞰大地。${profile.futureVision || '和平'}的景象映入眼帘,传奇才刚刚开始。`
|
||
}
|
||
};
|
||
|
||
const t = templates[requirements.style] || templates.career;
|
||
|
||
return {
|
||
id,
|
||
createdAt: new Date().toISOString(),
|
||
title: requirements.theme.substring(0, 10) + (requirements.style === 'fantasy' ? '·觉醒篇' : requirements.style === 'love' ? '·情缘篇' : '·逆袭篇'),
|
||
theme: requirements.theme,
|
||
style: requirements.style,
|
||
plot: t
|
||
};
|
||
},
|
||
|
||
/**
|
||
* Generate implementation path based on script.
|
||
*/
|
||
async generatePath(script, profile) {
|
||
await sleep(1500);
|
||
|
||
const hobby = (profile.hobbies && profile.hobbies.length > 0) ? profile.hobbies[0] : "关键技能";
|
||
|
||
return {
|
||
id: Date.now().toString(),
|
||
scriptId: script.id,
|
||
createdAt: new Date().toISOString(),
|
||
steps: [
|
||
{
|
||
phase: "第一阶段:沉淀与积累",
|
||
time: "第1-2个月",
|
||
content: `针对剧本中提到的"${hobby}",开始系统性学习。不要急于求成,利用${profile.mbti}擅长的深度思考,打好基础。`,
|
||
action: `购买两本高评分书籍或订阅一个专业专栏,每天坚持阅读学习45分钟。`,
|
||
resources: `专业书籍、在线MOOC平台`,
|
||
habit: `建立"日落复盘"机制,记录当天的收获。`
|
||
},
|
||
{
|
||
phase: "第二阶段:破局尝试",
|
||
time: "第3-6个月",
|
||
content: `正如剧本中"${script.plot.turning.substring(0, 10)}..."所描述的,寻找一个小型的实践机会。将知识转化为行动。`,
|
||
action: `完成一个最小可行性项目(Side Project)并在社交媒体分享。`,
|
||
resources: `GitHub/Behance/小红书等展示平台`,
|
||
habit: `每周连接一位同频的伙伴。`
|
||
},
|
||
{
|
||
phase: "第三阶段:爆发冲刺",
|
||
time: "第6-12个月",
|
||
content: `制造你的高光时刻。${profile.futureVision ? '向着"' + profile.futureVision + '"靠近' : '向着行业头部进发'}。主动承担高难度任务。`,
|
||
action: `参加一次行业比赛,或在团队中主导一个关键项目。`,
|
||
resources: `导师资源、行业峰会`,
|
||
habit: `冥想与可视化练习,强化自信心。`
|
||
},
|
||
{
|
||
phase: "第四阶段:愿景显化",
|
||
time: "1年后",
|
||
content: `将能力转化为影响力,实现"${script.theme}"。保持谦逊,同时不吝啬展示自己的光芒。`,
|
||
action: `整理你的方法论,开设分享会或撰写系列文章。`,
|
||
resources: `个人品牌渠道`,
|
||
habit: `终身学习,保持空杯心态。`
|
||
}
|
||
]
|
||
};
|
||
}
|
||
};
|