xiaozuoassistant 0.1.77 → 0.1.78

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/README.md CHANGED
@@ -86,6 +86,9 @@ xiaozuoAssistant start
86
86
 
87
87
  - 你可以通过 `config.json` 或 API (`/api/config`) 更新 LLM 配置。
88
88
  - 支持 OpenAI 兼容的多 provider(示例:`openai/deepseek/minimax/doubao/qwen/custom`),并会自动映射 baseURL。
89
+ - **配置项增强**:
90
+ - `maxHistoryMessages`: 控制发送给 LLM 的历史消息数量(默认 20),防止 Context Window 溢出。
91
+ - `maxToolIterations`: 限制工具调用的最大迭代次数(默认 15),防止死循环。
89
92
  - 可用环境变量:`XIAOZUO_LLM_API_KEY`(覆盖 `config.json` 中的 key)。
90
93
 
91
94
  ## 文档
@@ -64,7 +64,8 @@ catch (error) {
64
64
  requestTimeoutMs: 600000,
65
65
  maxRetries: 2,
66
66
  maxToolIterations: 200,
67
- maxHistoryMessages: 20
67
+ maxHistoryMessages: 20,
68
+ sessionWakeupHours: 24
68
69
  },
69
70
  logging: { level: 'info' },
70
71
  scheduler: { memoryMaintenanceCron: '0 0 * * *', sessionRetentionDays: 5 },
@@ -20,6 +20,25 @@ export class Brain {
20
20
  if (process.env.DEBUG)
21
21
  console.log('[Brain] Processing message:', newMessage);
22
22
  const defaultSystemPrompt = systemPrompt || config.systemPrompt || SYSTEM_PROMPT || 'You are xiaozuoAssistant, a helpful AI assistant. You can use tools to help users.';
23
+ // Check for long inactivity (Session Wake-up)
24
+ const sessionLastActive = context?.session?.lastActiveAt || 0;
25
+ const now = Date.now();
26
+ const hoursSinceActive = (now - sessionLastActive) / (1000 * 60 * 60);
27
+ const WAKEUP_THRESHOLD = config.llm.sessionWakeupHours ?? 24;
28
+ let wakeupContext = '';
29
+ if (sessionLastActive > 0 && hoursSinceActive > WAKEUP_THRESHOLD) {
30
+ if (process.env.DEBUG)
31
+ console.log(`[Brain] Session wake-up detected (${hoursSinceActive.toFixed(1)}h > ${WAKEUP_THRESHOLD}h). Generating recap...`);
32
+ // Use recent history for quick summary, or could query Vector DB for deeper context
33
+ // For now, simple summary of recent messages to refresh context
34
+ const recentText = history.slice(-50).map(m => `${m.role}: ${m.content}`).join('\n');
35
+ if (recentText.length > 100) {
36
+ const summary = await this.generateSummary(recentText);
37
+ if (summary) {
38
+ wakeupContext = `\n\n[System Notice]: The user has returned after ${Math.floor(hoursSinceActive)} hours. Here is a brief recap of the previous conversation context to help you catch up:\n${summary}`;
39
+ }
40
+ }
41
+ }
23
42
  // Convert history messages to the format expected by OpenAI
24
43
  // Strategy: Keep last N messages to avoid context window overflow
25
44
  // TODO: A better strategy would be token-based truncation.
@@ -36,7 +55,7 @@ export class Brain {
36
55
  return msg;
37
56
  });
38
57
  const messages = [
39
- { role: 'system', content: defaultSystemPrompt },
58
+ { role: 'system', content: defaultSystemPrompt + wakeupContext },
40
59
  ...messageHistory,
41
60
  { role: 'user', content: newMessage }
42
61
  ];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "xiaozuoassistant",
3
3
  "private": false,
4
4
  "description": "Your personal, locally-hosted AI assistant for office productivity.",
5
- "version": "0.1.77",
5
+ "version": "0.1.78",
6
6
  "author": "mantle.lau",
7
7
  "license": "MIT",
8
8
  "repository": {