koishi-plugin-chatluna-affinity 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -23,7 +23,9 @@ export interface Config {
23
23
  triggerNicknames: string[];
24
24
  useLastAffinity: boolean;
25
25
  historyMessageCount: number;
26
- personaPrompt: string;
26
+ personaSource: 'none' | 'chatluna' | 'custom';
27
+ personaChatlunaPreset: string;
28
+ personaCustomPreset: string;
27
29
  relationshipVariableName: string;
28
30
  relationships: Array<{
29
31
  initialAffinity: number | null;
package/lib/index.js CHANGED
@@ -28,6 +28,27 @@ function apply(ctx, config) {
28
28
  const affinityProvider = createAffinityProvider({ config, cache, store });
29
29
  const relationshipProvider = createRelationshipProvider({ config, store });
30
30
 
31
+ const resolvePersonaPreset = (session) => {
32
+ const source = config.personaSource || 'none';
33
+ if (source === 'chatluna') {
34
+ let presetName = String(config.personaChatlunaPreset ?? '').trim();
35
+ if (presetName === '无') presetName = '';
36
+ if (presetName) {
37
+ const presetRef = ctx.chatluna?.preset?.getPreset?.(presetName);
38
+ const presetValue = presetRef?.value;
39
+ if (typeof presetValue === 'string') return presetValue;
40
+ if (typeof presetValue?.rawText === 'string') return presetValue.rawText;
41
+ if (presetValue?.config?.prompt) return presetValue.config.prompt;
42
+ }
43
+ return ctx.chatluna?.personaPrompt || '';
44
+ }
45
+ if (source === 'custom') {
46
+ const text = String(config.personaCustomPreset ?? '').trim();
47
+ return text;
48
+ }
49
+ return '';
50
+ };
51
+
31
52
  const globalGuard = async (session, next) => {
32
53
  if (!config.enableAutoBlacklist) return next();
33
54
  const platform = session?.platform;
@@ -79,7 +100,8 @@ function apply(ctx, config) {
79
100
  renderTemplate,
80
101
  getMessageContent,
81
102
  getModel,
82
- log
103
+ log,
104
+ resolvePersonaPreset
83
105
  });
84
106
 
85
107
  ctx.middleware(middleware);
package/lib/middleware.js CHANGED
@@ -67,7 +67,7 @@ const tryBlacklistUser = async (ctx, session, store, cache, log) => {
67
67
  return { recorded: Boolean(recorded) };
68
68
  };
69
69
 
70
- function createAnalysisMiddleware(ctx, config, { store, history, cache, getModel, renderTemplate, getMessageContent, log }) {
70
+ function createAnalysisMiddleware(ctx, config, { store, history, cache, getModel, renderTemplate, getMessageContent, log, resolvePersonaPreset }) {
71
71
  const debugEnabled = config.debugLogging;
72
72
 
73
73
  const clampValue = (value, low, high) => Math.min(high, Math.max(low, value));
@@ -114,7 +114,7 @@ function createAnalysisMiddleware(ctx, config, { store, history, cache, getModel
114
114
  historyText: historyLines.join('\n'),
115
115
  historyJson: JSON.stringify(historyLines, null, 2),
116
116
  userMessage: session.content ?? '',
117
- personaPrompt: config.personaPrompt ?? ''
117
+ personaPreset: resolvePersonaPreset(session)
118
118
  });
119
119
 
120
120
  const model = getModel();
package/lib/schema.js CHANGED
@@ -36,18 +36,26 @@ const AffinitySchema = Schema.object({
36
36
  analysisPrompt: Schema.string()
37
37
  .role('textarea')
38
38
  .default(
39
- '你是好感度管家,需要根据上下文评估是否调整好感度。\n- 仔细阅读最近若干条群聊消息,聚焦语气、内容、语境与互动意图;\n- 只有当用户展现出明确、具体的善意或贡献时(如感谢、称赞、帮助解决问题、分享价值信息、表达真诚关心),才考虑增加;\n- 若用户只是礼貌问候、例行回应、轻度调侃或重复旧话题,可保持不变;\n- 对于冒犯、敷衍、抄袭、频繁打扰、传播负面情绪或破坏氛围的行为,应减少;\n- 增加幅度不超过 {{maxIncreasePerMessage}} ,减少幅度不超过 {{maxDecreasePerMessage}} ,并保持在提供的范围内;\n- 在总结理由时,指明触发增减的具体言辞或行为;\n- 使用 action 表示行为:increase 增加、decrease 减少、hold 保持。\n\n角色设定:{{personaPrompt}}\n\n当前好感度:{{currentAffinity}} (范围 {{minAffinity}} ~ {{maxAffinity}})\n最近 {{historyCount}} 条消息(旧 -> 新):\n{{historyText}}\n\n本次用户消息:\n{{userMessage}}\n\n请仅输出 JSON:{"delta": 整数, "action": "increase|decrease|hold", "reason": "简短中文原因"}。'
39
+ '你是好感度管家,需要根据上下文评估是否调整好感度。\n- 仔细阅读最近若干条群聊消息,聚焦语气、内容、语境与互动意图;\n- 始终以“人设”描述的性格作为判断基准,任何增减决策都必须符合该人设的价值观与反应习惯;\n- 只有当用户展现出明确、具体且与人设契合的善意或贡献(如真诚称赞、贴心关怀、实际帮助、提供人设喜好的内容)时,才考虑增加;\n- 若互动只是礼貌问候、例行回应、轻度调侃或重复旧话题且未触发人设偏好,可保持不变;\n- 对于人设会视为冒犯、敷衍、抄袭、频繁打扰或传播负面情绪的行为,应减少;\n- 增加幅度不超过 {{maxIncreasePerMessage}} ,减少幅度不超过 {{maxDecreasePerMessage}} ,并保持在提供的范围内;\n- 在总结理由时,明确触发增减的具体言辞或行为,并以该人设的第一人称语气说明“我”为什么会这么做;\n- 使用 action 表示行为:increase 增加、decrease 减少、hold 保持。\n\n人设:{{personaPreset}}\n\n当前好感度:{{currentAffinity}} (范围 {{minAffinity}} ~ {{maxAffinity}})\n最近 {{historyCount}} 条消息(旧 -> 新):\n{{historyText}}\n\n本次用户消息:\n{{userMessage}}\n\n请仅输出 JSON:{"delta": 整数, "action": "increase|decrease|hold", "reason": "简短中文原因"}。'
40
40
  )
41
41
  .description('好感度分析主提示词'),
42
- personaPrompt: Schema.string()
42
+ personaSource: Schema.union([
43
+ Schema.const('none').description('不注入预设'),
44
+ Schema.const('chatluna').description('使用 ChatLuna 主插件预设'),
45
+ Schema.const('custom').description('使用自定义预设')
46
+ ]).default('none').description('人设注入来源'),
47
+ personaChatlunaPreset: Schema.dynamic('preset')
48
+ .default('无')
49
+ .hidden((_, cfg) => (cfg?.personaSource || 'none') !== 'chatluna')
50
+ .description('当选择主插件预设时,指定要注入的 ChatLuna 预设'),
51
+ personaCustomPreset: Schema.string()
43
52
  .role('textarea')
44
- .default('你是一位温暖可靠的伙伴,会根据好感度高低调整语气:好感度越高越亲近,越低越保持礼貌。')
45
- .description('补充的人设提示词,会注入到分析提示词中'),
53
+ .default('')
54
+ .hidden((_, cfg) => (cfg?.personaSource || 'none') !== 'custom')
55
+ .description('当选择自定义预设时注入的文本内容'),
46
56
  debugLogging: Schema.boolean().default(false).description('输出调试日志'),
47
57
  registerAffinityTool: Schema.boolean().default(false).description('注册 ChatLuna 工具:调整好感度'),
48
- registerBlacklistTool: Schema.boolean().default(false).description('注册 ChatLuna 工具:管理黑名单'),
49
- rankDefaultLimit: Schema.number().default(10).min(1).max(50).description('排行榜默认展示人数'),
50
- rankRenderAsImage: Schema.boolean().default(false).description('排行榜默认渲染为图片')
58
+ registerBlacklistTool: Schema.boolean().default(false).description('注册 ChatLuna 工具:管理黑名单')
51
59
  }).description('好感度设置');
52
60
 
53
61
  const RelationshipSchema = Schema.object({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chatluna-affinity",
3
3
  "description": "为 ChatLuna 提供{好感度}与{关系}变量并提供对应的工具调用和低好感自动拉黑功能。仅测试过伪装插件。",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -27,7 +27,9 @@
27
27
  | `maxDecreasePerMessage` | 单次允许减少的最大幅度(提示词变量 `{{maxDecreasePerMessage}}`) |
28
28
  | `model` | 用于分析的 ChatLuna 模型 |
29
29
  | `analysisPrompt` | 主提示词模板,支持 `{{currentAffinity}}` 等占位符 |
30
- | `personaPrompt` | 机器人的人设补充说明 |
30
+ | `personaSource` | 可选人设预设来源(`none` / `chatluna` / `custom`) |
31
+ | `personaChatlunaPreset` | 当来源为 `chatluna` 时注入的预设名称 |
32
+ | `personaCustomPreset` | 当来源为 `custom` 时注入的自定义文本 |
31
33
  | `triggerNicknames` | 触发分析的 bot 昵称列表(默认含 ChatLuna 配置的昵称/@ 名) |
32
34
  | `useLastAffinity` | 开启后变量能立即返回上一次结果(无需等待分析完成) |
33
35
  | `historyMessageCount` | 提供给模型的历史消息条数(从数据库或 group-analysis 插件取得) |