xiaozuoassistant 0.2.53 → 0.2.55

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.
@@ -114,9 +114,11 @@ export class FeishuChannel extends BaseChannel {
114
114
  const fs = require('fs-extra');
115
115
  const configLoader = require('../config/loader.js').config;
116
116
  const workspacePath = path.resolve(configLoader.workspace || path.join(process.cwd(), 'workspace'));
117
- await fs.ensureDir(workspacePath);
117
+ const botDownloadDir = botName || appId;
118
+ const finalDownloadPath = path.join(workspacePath, 'downloads', botDownloadDir);
119
+ await fs.ensureDir(finalDownloadPath);
118
120
  // 防止文件名冲突,可以加上时间戳前缀,但为了用户体验,我们保留原名,或者加上一个短哈希
119
- const savePath = path.join(workspacePath, fileName);
121
+ const savePath = path.join(finalDownloadPath, fileName);
120
122
  this.emitMessage(sessionId, `收到文件: ${fileName},正在下载到工作区...`, botName);
121
123
  try {
122
124
  const res = await client.im.messageResource.get({
@@ -1,6 +1,12 @@
1
1
  export const SYSTEM_PROMPT = `
2
2
  你现在是 我的个人AI助手,叫xiaozuoAssistant。
3
3
 
4
+ 运行环境与能力:
5
+ - 你运行在用户的本地机器上(不是纯云端聊天机器人)。
6
+ - 你可以使用内置工具在“当前会话 workspace”内列目录、读取文件、写入文件。
7
+ - 不要让用户去手动运行 ls/cat/find 等命令;应优先调用工具完成。
8
+ - 若用户给的路径不在 workspace 内,请解释这是安全限制,并指导用户切换会话 workspace 或把文件放入 workspace。
9
+
4
10
  核心规则:
5
11
  1. 所有记忆完全本地存储,不上传任何内容到云端。
6
12
  2. 默认工作模式:优先使用 office_work 类别的记忆。
@@ -25,9 +25,14 @@ export class AgentRuntime {
25
25
  if (context?.metadata?.botName) {
26
26
  identityContext = `\n\n[System Identity]: Your name is "${context.metadata.botName}". You are acting as this bot. You must refer to yourself strictly as "${context.metadata.botName}" when introducing yourself or when asked about your identity. Do not use the generic name "xiaozuoAssistant" unless explicitly necessary.`;
27
27
  }
28
+ const effectiveWorkspace = String(context?.metadata?.workspace ||
29
+ context?.session?.workspace ||
30
+ config.workspace ||
31
+ '').trim();
32
+ const localRuntimeContext = `\n\n[Local Runtime]\nYou are running on the user's local machine (not a cloud-only assistant).\nYou can use built-in tools to list/read/write files within the current session workspace.\nWorkspace: ${effectiveWorkspace || '(not set)'}\nRules:\n- When asked to list/read/write files, use the provided tools instead of asking the user to run shell commands.\n- Never claim you are unable to access the local filesystem in general.\n- If a user provides a path outside the current workspace, explain that access is limited to the workspace for safety, and ask the user to switch the session workspace or move files into the workspace.\n- For files sent from Feishu, check workspace/downloads/<botName>/ first.\n`.trimEnd();
28
33
  const finalSystemPrompt = contextPrompt
29
- ? `${this.systemPrompt}${identityContext}\n${contextPrompt}`
30
- : `${this.systemPrompt}${identityContext}`;
34
+ ? `${this.systemPrompt}${identityContext}${localRuntimeContext}\n${contextPrompt}`
35
+ : `${this.systemPrompt}${identityContext}${localRuntimeContext}`;
31
36
  const messages = [
32
37
  { role: 'system', content: finalSystemPrompt },
33
38
  ...history.map(m => ({ role: m.role, content: m.content, name: m.name, tool_call_id: m.tool_call_id, tool_calls: m.tool_calls })),
@@ -49,6 +49,11 @@ export class Brain {
49
49
  if (context?.metadata?.botName) {
50
50
  identityContext = `\n\n[System Identity]: Your name is "${context.metadata.botName}". You are acting as this bot. You must refer to yourself strictly as "${context.metadata.botName}" when introducing yourself or when asked about your identity. Do not use the generic name "xiaozuoAssistant" unless explicitly necessary.`;
51
51
  }
52
+ const effectiveWorkspace = String(context?.metadata?.workspace ||
53
+ context?.session?.workspace ||
54
+ config.workspace ||
55
+ '').trim();
56
+ const localRuntimeContext = `\n\n[Local Runtime]\nYou are running on the user's local machine (not a cloud-only assistant).\nYou can use built-in tools to list/read/write files within the current session workspace.\nWorkspace: ${effectiveWorkspace || '(not set)'}\nRules:\n- When asked to list/read/write files, use the provided tools (fs_list_directory / fs_read_file / fs_write_file) instead of asking the user to run shell commands.\n- Never claim you are unable to access the local filesystem in general.\n- If a user provides a path outside the current workspace, explain that access is limited to the workspace for safety, and ask the user to switch the session workspace or move files into the workspace.\n- For files sent from Feishu, check workspace/downloads/<botName>/ first.\n`.trimEnd();
52
57
  // Convert history messages to the format expected by OpenAI
53
58
  // Strategy: Keep last N messages to avoid context window overflow
54
59
  // TODO: A better strategy would be token-based truncation.
@@ -65,7 +70,7 @@ export class Brain {
65
70
  return msg;
66
71
  });
67
72
  const messages = [
68
- { role: 'system', content: defaultSystemPrompt + identityContext + wakeupContext },
73
+ { role: 'system', content: defaultSystemPrompt + identityContext + localRuntimeContext + wakeupContext },
69
74
  ...messageHistory,
70
75
  { role: 'user', content: newMessage }
71
76
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.53",
3
+ "version": "0.2.55",
4
4
  "description": "A local-first personal AI assistant with multi-channel support and enhanced memory.",
5
5
  "author": "mantle.lau",
6
6
  "license": "MIT",