@yeaft/webchat-agent 1.0.422 → 1.0.424

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.
@@ -137,6 +137,17 @@ async function handleTerminalResponse(agentId, msg, routeKey) {
137
137
  }
138
138
  }
139
139
 
140
+ async function handleAgentDirectoryPickerResponse(agentId, msg) {
141
+ const pending = consumeWorkbenchRequest({
142
+ agentId,
143
+ requestId: msg._workbenchRequestId,
144
+ responseType: msg.type,
145
+ routeKey: `agent-directory-picker:${agentId}`,
146
+ });
147
+ if (!pending || pending.requestType !== 'agent_directory_picker') return;
148
+ await sendToPendingClient(agentId, msg, pending);
149
+ }
150
+
140
151
  async function handleOneShotResponse(agentId, msg, routeKey) {
141
152
  const pending = consumeWorkbenchRequest({
142
153
  agentId,
@@ -186,6 +197,13 @@ export async function handleAgentFileTerminal(agentId, agent, rawMsg) {
186
197
  return true;
187
198
  }
188
199
 
200
+ if (msg.type === 'directory_listing'
201
+ && msg.conversationId === '_workdir_picker'
202
+ && msg._workbenchRequestId) {
203
+ await handleAgentDirectoryPickerResponse(agentId, msg);
204
+ return true;
205
+ }
206
+
189
207
  // `_workbench:` is reserved for Server-authored route conversations. An
190
208
  // invalid or cross-Agent value is not a legacy conversation.
191
209
  if (typeof msg.conversationId === 'string' && msg.conversationId.startsWith('_workbench:')) {
@@ -1,4 +1,5 @@
1
1
  import { CONFIG } from '../config.js';
2
+ import { agents } from '../context.js';
2
3
  import {
3
4
  sendToWebClient, forwardToAgent,
4
5
  verifyConversationOwnership, getCachedDir
@@ -37,6 +38,8 @@ async function denyWorkbenchRoute(client, msg) {
37
38
  await sendToWebClient(client, { type: 'error', message: 'Invalid Workbench Session route' });
38
39
  }
39
40
 
41
+ const AGENT_DIRECTORY_PICKER_CONVERSATION = '_workdir_picker';
42
+
40
43
  const RESPONSE_TYPES = Object.freeze({
41
44
  terminal_create: ['terminal_created', 'terminal_error'],
42
45
  read_file: ['file_content'],
@@ -248,6 +251,47 @@ export async function handleClientWorkbench(clientId, client, msg, checkAgentAcc
248
251
  if (!dirAgentId) return;
249
252
  if (!await checkAgentAccess(dirAgentId)) return;
250
253
 
254
+ const isAgentDirectoryPicker = msg.directoryPickerScope === 'agent'
255
+ && msg.conversationId === AGENT_DIRECTORY_PICKER_CONVERSATION
256
+ && !msg.workbenchRoute
257
+ && typeof msg.requestId === 'string'
258
+ && msg.requestId.length > 0;
259
+ if (isAgentDirectoryPicker) {
260
+ const agent = agents.get(dirAgentId);
261
+ const defaultWorkDir = typeof agent?.workDir === 'string' ? agent.workDir : '';
262
+ const correlationKey = `agent-directory-picker:${dirAgentId}`;
263
+ const internalRequestId = registerWorkbenchRequest({
264
+ agentId: dirAgentId,
265
+ clientId,
266
+ userId: client.userId,
267
+ routeKey: correlationKey,
268
+ conversationId: AGENT_DIRECTORY_PICKER_CONVERSATION,
269
+ workspaceGeneration: correlationKey,
270
+ route: null,
271
+ role: client.role,
272
+ requestType: 'agent_directory_picker',
273
+ expectedResponseTypes: ['directory_listing'],
274
+ publicRequestId: msg.requestId,
275
+ });
276
+ if (!internalRequestId) return;
277
+ const canonical = {
278
+ type: 'list_directory',
279
+ agentId: dirAgentId,
280
+ conversationId: AGENT_DIRECTORY_PICKER_CONVERSATION,
281
+ directoryPickerScope: 'agent',
282
+ dirPath: typeof msg.dirPath === 'string' ? msg.dirPath : defaultWorkDir,
283
+ workDir: defaultWorkDir,
284
+ _workbenchRequestId: internalRequestId,
285
+ };
286
+ try {
287
+ await forwardToAgent(dirAgentId, canonical);
288
+ } catch (error) {
289
+ deleteWorkbenchRequest({ agentId: dirAgentId, requestId: internalRequestId });
290
+ throw error;
291
+ }
292
+ return;
293
+ }
294
+
251
295
  const resolved = resolveWorkbenchRequest(client, msg, dirAgentId);
252
296
  if (!resolved) {
253
297
  await denyWorkbenchRoute(client, msg);
@@ -1 +1 @@
1
- {"version":"1.0.422"}
1
+ {"version":"1.0.424"}