xiaozuoassistant 0.2.45 → 0.2.46

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.
@@ -15,9 +15,9 @@ export class BaseChannel {
15
15
  onMessage(handler) {
16
16
  this.messageHandler = handler;
17
17
  }
18
- emitMessage(sessionId, message) {
18
+ emitMessage(sessionId, message, botName) {
19
19
  if (this.messageHandler) {
20
- this.messageHandler(sessionId, message);
20
+ this.messageHandler(sessionId, message, botName);
21
21
  }
22
22
  }
23
23
  }
@@ -143,7 +143,7 @@ export class FeishuChannel extends BaseChannel {
143
143
  }
144
144
  return;
145
145
  }
146
- this.emitMessage(sessionId, content);
146
+ this.emitMessage(sessionId, content, botName);
147
147
  }
148
148
  catch (e) {
149
149
  console.error(`[Feishu-${botName}] Failed to parse message content:`, e);
@@ -20,9 +20,14 @@ export class AgentRuntime {
20
20
  return this.skills.map(skill => skill.toJSON());
21
21
  }
22
22
  async process(history, newMessage, contextPrompt, context) {
23
+ // 如果上下文中包含 botName,将其注入到系统提示词中
24
+ let identityContext = '';
25
+ if (context?.metadata?.botName) {
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
+ }
23
28
  const finalSystemPrompt = contextPrompt
24
- ? `${this.systemPrompt}\n${contextPrompt}`
25
- : this.systemPrompt;
29
+ ? `${this.systemPrompt}${identityContext}\n${contextPrompt}`
30
+ : `${this.systemPrompt}${identityContext}`;
26
31
  const messages = [
27
32
  { role: 'system', content: finalSystemPrompt },
28
33
  ...history.map(m => ({ role: m.role, content: m.content, name: m.name, tool_call_id: m.tool_call_id, tool_calls: m.tool_calls })),
@@ -44,6 +44,11 @@ export class Brain {
44
44
  }
45
45
  }
46
46
  }
47
+ // 如果上下文中包含 botName,将其注入到系统提示词中
48
+ let identityContext = '';
49
+ if (context?.metadata?.botName) {
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
+ }
47
52
  // Convert history messages to the format expected by OpenAI
48
53
  // Strategy: Keep last N messages to avoid context window overflow
49
54
  // TODO: A better strategy would be token-based truncation.
@@ -60,7 +65,7 @@ export class Brain {
60
65
  return msg;
61
66
  });
62
67
  const messages = [
63
- { role: 'system', content: defaultSystemPrompt + wakeupContext },
68
+ { role: 'system', content: defaultSystemPrompt + identityContext + wakeupContext },
64
69
  ...messageHistory,
65
70
  { role: 'user', content: newMessage }
66
71
  ];
@@ -18,7 +18,7 @@ export class TaskQueue {
18
18
  this.chains.set(key, next);
19
19
  }
20
20
  async process(task) {
21
- const { run, channel } = task;
21
+ const { run, channel, botName } = task;
22
22
  try {
23
23
  const session = await memory.getSession(run.sessionId);
24
24
  if (!session) {
@@ -56,7 +56,8 @@ ${context}`;
56
56
  metadata: {
57
57
  workspace: session.meta.workspace,
58
58
  alias: session.meta.alias,
59
- runId: run.id
59
+ runId: run.id,
60
+ botName: botName
60
61
  }
61
62
  };
62
63
  const responseContent = await brain.processMessage(session.messages, run.userContent, enhancedSystemPrompt, ctx);
@@ -376,13 +376,14 @@ app.post('/api/config', async (req, res) => {
376
376
  const feishuChannel = new FeishuChannel();
377
377
  channels.push(feishuChannel);
378
378
  await feishuChannel.start();
379
- feishuChannel.onMessage((sessionId, message) => {
379
+ feishuChannel.onMessage((sessionId, message, botName) => {
380
380
  eventBus.emitEvent({
381
381
  type: 'message',
382
382
  payload: { content: message },
383
383
  channel: feishuChannel.name,
384
384
  sessionId: sessionId,
385
- timestamp: Date.now()
385
+ timestamp: Date.now(),
386
+ botName: botName
386
387
  });
387
388
  });
388
389
  }
@@ -775,13 +776,14 @@ for (const ch of channels) {
775
776
  channels.forEach(channel => {
776
777
  channel.start();
777
778
  // 监听通道消息 -> 发送到 EventBus
778
- channel.onMessage((sessionId, message) => {
779
+ channel.onMessage((sessionId, message, botName) => {
779
780
  eventBus.emitEvent({
780
781
  type: 'message',
781
782
  payload: { content: message },
782
783
  channel: channel.name,
783
784
  sessionId: sessionId,
784
- timestamp: Date.now()
785
+ timestamp: Date.now(),
786
+ botName: botName
785
787
  });
786
788
  });
787
789
  });
@@ -837,16 +839,18 @@ eventBus.onEvent('message', async (event) => {
837
839
  payload: { runId: run.id },
838
840
  channel: channelName,
839
841
  sessionId,
840
- timestamp: Date.now()
842
+ timestamp: Date.now(),
843
+ botName: event.botName
841
844
  });
842
845
  eventBus.emitEvent({
843
846
  type: 'run_status',
844
847
  payload: { runId: run.id, status: 'queued' },
845
848
  channel: channelName,
846
849
  sessionId,
847
- timestamp: Date.now()
850
+ timestamp: Date.now(),
851
+ botName: event.botName
848
852
  });
849
- taskQueue.enqueue({ run, channel: channelName });
853
+ taskQueue.enqueue({ run, channel: channelName, botName: event.botName });
850
854
  }
851
855
  catch (error) {
852
856
  console.error('Error processing message:', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaozuoassistant",
3
- "version": "0.2.45",
3
+ "version": "0.2.46",
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",