@yeaft/webchat-agent 1.0.415 → 1.0.417

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.
@@ -6,14 +6,16 @@ import { authenticateRequest } from './auth/request-auth.js';
6
6
  import { encodeKey } from './encryption.js';
7
7
  import { userDb } from './database.js';
8
8
  import { agents, clearYeaftDebugRequestsForClient, webClients, isHeartbeatMessageType, trackRequest } from './context.js';
9
- import { applyClientHello, WORKBENCH_ROUTE_PROTOCOL } from './client-protocol.js';
9
+ import { applyClientHello, BROWSER_RUNTIME_PROTOCOL, WORKBENCH_ROUTE_PROTOCOL } from './client-protocol.js';
10
10
  import { clearWorkbenchCorrelationsForClient } from './workbench-correlation.js';
11
+ import { clearBrowserRuntimeForClient } from './browser-runtime-routes.js';
11
12
  import {
12
13
  parseMessage, sendToWebClient, sendToAgent,
13
14
  broadcastAgentList, resolveAgentAccessError
14
15
  } from './ws-utils.js';
15
16
  import { handleClientConversation } from './handlers/client-conversation.js';
16
17
  import { handleClientWorkbench } from './handlers/client-workbench.js';
18
+ import { CLIENT_BROWSER_TYPES, handleClientBrowser } from './handlers/client-browser.js';
17
19
  import { handleClientMisc } from './handlers/client-misc.js';
18
20
  import { clearWorkCenterRequestsForClient, handleClientWorkCenter } from './handlers/client-work-center.js';
19
21
  import { recordPerfTraceEvent } from './perf-trace.js';
@@ -64,7 +66,11 @@ export function handleWebConnection(ws, url, req = {}) {
64
66
  }
65
67
  }
66
68
 
69
+ const connectionId = randomUUID();
67
70
  webClients.set(clientId, {
71
+ id: clientId,
72
+ connectionId,
73
+ connectionGeneration: connectionId,
68
74
  ws,
69
75
  authenticated,
70
76
  username,
@@ -79,8 +85,9 @@ export function handleWebConnection(ws, url, req = {}) {
79
85
  // `false` when the client sends `client_hello { plaintextOk: true }`
80
86
  // — see early dispatch in handleWebMessage.
81
87
  encryptOutbound: true,
82
- // Explicit Workbench protocol negotiation. Zero means legacy Web.
88
+ // Explicit protocols have no omission-based downgrade for security fields.
83
89
  workbenchRouteProtocol: 0,
90
+ browserRuntimeProtocol: 0,
84
91
  });
85
92
 
86
93
  // 心跳响应处理
@@ -108,6 +115,8 @@ export function handleWebConnection(ws, url, req = {}) {
108
115
  acceptPlaintext: true,
109
116
  yeaftSessionInventoryComplete: true,
110
117
  workbenchRouteProtocol: WORKBENCH_ROUTE_PROTOCOL,
118
+ browserRuntimeProtocol: BROWSER_RUNTIME_PROTOCOL,
119
+ browserRuntimeEnabled: CONFIG.browserRuntime.enabled,
111
120
  }));
112
121
  setTimeout(() => broadcastAgentList(), 100);
113
122
  } else {
@@ -169,6 +178,24 @@ export function handleWebConnection(ws, url, req = {}) {
169
178
  }
170
179
  clearWorkCenterRequestsForClient(client);
171
180
  clearYeaftDebugRequestsForClient(clientId);
181
+ const browserPeers = clearBrowserRuntimeForClient(client);
182
+ for (const peer of browserPeers) {
183
+ const agent = agents.get(peer.agentId);
184
+ if (!agent) continue;
185
+ void sendToAgent(agent, {
186
+ type: 'browser_peer_detach',
187
+ agentId: peer.agentId,
188
+ browserSessionId: peer.browserSessionId,
189
+ peerId: peer.peerId,
190
+ connectionGeneration: peer.connectionGeneration,
191
+ serverIdentity: {
192
+ ownerUserId: peer.ownerUserId,
193
+ clientId: peer.clientId,
194
+ webConnectionId: peer.webConnectionId,
195
+ webConnectionGeneration: peer.webConnectionGeneration,
196
+ },
197
+ }).catch(error => console.warn('[BrowserRuntime] peer disconnect cleanup failed:', error.message));
198
+ }
172
199
  const ownedTerminals = clearWorkbenchCorrelationsForClient(clientId);
173
200
  for (const owner of ownedTerminals) {
174
201
  const agent = agents.get(owner.agentId);
@@ -192,6 +219,7 @@ export function handleWebConnection(ws, url, req = {}) {
192
219
 
193
220
  // Workbench 功能(terminal、file、git、proxy)仅 admin/pro 可用
194
221
  const WORKBENCH_TYPES = new Set([
222
+ ...CLIENT_BROWSER_TYPES,
195
223
  'terminal_create', 'terminal_input', 'terminal_resize', 'terminal_close',
196
224
  'read_file', 'write_file', 'create_file', 'delete_files', 'move_files', 'copy_files', 'upload_to_dir', 'file_search',
197
225
  'git_status', 'git_diff', 'git_add', 'git_reset', 'git_restore', 'git_commit', 'git_push',
@@ -220,6 +248,8 @@ async function handleWebMessage(clientId, msg) {
220
248
  await sendToWebClient(client, {
221
249
  type: 'client_hello_ack',
222
250
  workbenchRouteProtocol: client.workbenchRouteProtocol,
251
+ browserRuntimeProtocol: client.browserRuntimeProtocol,
252
+ browserRuntimeEnabled: CONFIG.browserRuntime.enabled,
223
253
  });
224
254
  return;
225
255
  }
@@ -246,6 +276,7 @@ async function handleWebMessage(clientId, msg) {
246
276
 
247
277
  // Dispatch to handler sub-modules
248
278
  if (await handleClientConversation(clientId, client, msg, checkAgentAccess)) return;
279
+ if (await handleClientBrowser(client, msg, checkAgentAccess)) return;
249
280
  if (await handleClientWorkbench(clientId, client, msg, checkAgentAccess)) return;
250
281
  if (await handleClientWorkCenter(client, msg, checkAgentAccess)) return;
251
282
  if (await handleClientMisc(clientId, client, msg, checkAgentAccess)) return;
@@ -1 +1 @@
1
- {"version":"1.0.415"}
1
+ {"version":"1.0.417"}