@yeaft/webchat-agent 1.0.408 → 1.0.409

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.
@@ -31,7 +31,8 @@ export async function handleAgentFileTerminal(agentId, agent, msg) {
31
31
  }
32
32
 
33
33
  // File operation messages
34
- case 'file_content':
34
+ case 'file_content': {
35
+ let fwdMsg = { ...msg, agentId };
35
36
  if (msg.binary) {
36
37
  // Binary file: cache on server, forward fileId instead of base64 content
37
38
  const fileId = randomUUID();
@@ -45,10 +46,13 @@ export async function handleAgentFileTerminal(agentId, agent, msg) {
45
46
  token
46
47
  });
47
48
  console.log(`[Server] Cached binary preview: fileId=${fileId}, mime=${msg.mimeType}, path=${msg.filePath}`);
48
- const fwdMsg = {
49
+ fwdMsg = {
49
50
  type: 'file_content',
51
+ agentId,
50
52
  conversationId: msg.conversationId,
53
+ requestId: msg.requestId,
51
54
  _requestUserId: msg._requestUserId,
55
+ _requestClientId: msg._requestClientId,
52
56
  filePath: msg.filePath,
53
57
  requestedFilePath: msg.requestedFilePath,
54
58
  binary: true,
@@ -56,17 +60,34 @@ export async function handleAgentFileTerminal(agentId, agent, msg) {
56
60
  previewToken: token,
57
61
  mimeType: msg.mimeType
58
62
  };
59
- await forwardToClients(agentId, msg.conversationId, fwdMsg);
60
63
  } else {
61
64
  console.log(`[Server] Forwarding file_content to clients, conv=${msg.conversationId}, path=${msg.filePath}`);
62
- await forwardToClients(agentId, msg.conversationId, msg);
65
+ }
66
+ const targetClient = fwdMsg._requestClientId ? webClients.get(fwdMsg._requestClientId) : null;
67
+ const targetMatchesUser = !fwdMsg._requestUserId || targetClient?.userId === fwdMsg._requestUserId;
68
+ if (targetClient?.authenticated && targetMatchesUser) {
69
+ const { _requestClientId, _requestUserId, ...cleanMsg } = fwdMsg;
70
+ await sendToWebClient(targetClient, cleanMsg);
71
+ } else {
72
+ const { _requestClientId, ...fallbackMsg } = fwdMsg;
73
+ await forwardToClients(agentId, msg.conversationId, fallbackMsg);
63
74
  }
64
75
  break;
76
+ }
65
77
 
66
78
  case 'file_saved': {
67
79
  // Phase 4: 文件保存后失效父目录缓存
68
80
  invalidateParentDirCache(agentId, msg.filePath);
69
- await forwardToClients(agentId, msg.conversationId, msg);
81
+ const fwdMsg = { ...msg, agentId };
82
+ const targetClient = msg._requestClientId ? webClients.get(msg._requestClientId) : null;
83
+ const targetMatchesUser = !msg._requestUserId || targetClient?.userId === msg._requestUserId;
84
+ if (targetClient?.authenticated && targetMatchesUser) {
85
+ const { _requestClientId, _requestUserId, ...cleanMsg } = fwdMsg;
86
+ await sendToWebClient(targetClient, cleanMsg);
87
+ } else {
88
+ const { _requestClientId, ...fallbackMsg } = fwdMsg;
89
+ await forwardToClients(agentId, msg.conversationId, fallbackMsg);
90
+ }
70
91
  break;
71
92
  }
72
93
 
@@ -57,7 +57,12 @@ export async function handleClientWorkbench(clientId, client, msg, checkAgentAcc
57
57
  if (!await checkAgentAccess(fileAgentId)) return;
58
58
  const fileConvId = msg.conversationId || client.currentConversation || '_explorer';
59
59
  console.log(`[Server] Forwarding read_file to agent ${fileAgentId}, conv=${fileConvId}, path=${msg.filePath}`);
60
- await forwardToAgent(fileAgentId, { ...msg, conversationId: fileConvId, _requestUserId: client.userId });
60
+ await forwardToAgent(fileAgentId, {
61
+ ...msg,
62
+ conversationId: fileConvId,
63
+ _requestUserId: client.userId,
64
+ _requestClientId: clientId,
65
+ });
61
66
  break;
62
67
  }
63
68
 
@@ -74,7 +79,12 @@ export async function handleClientWorkbench(clientId, client, msg, checkAgentAcc
74
79
  return;
75
80
  }
76
81
  }
77
- await forwardToAgent(writeAgentId, { ...msg, conversationId: writeConvId, _requestUserId: client.userId });
82
+ await forwardToAgent(writeAgentId, {
83
+ ...msg,
84
+ conversationId: writeConvId,
85
+ _requestUserId: client.userId,
86
+ _requestClientId: clientId,
87
+ });
78
88
  break;
79
89
  }
80
90
 
@@ -1 +1 @@
1
- {"version":"1.0.408"}
1
+ {"version":"1.0.409"}