@yeaft/webchat-agent 1.0.500 → 1.0.502

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "1.0.500",
3
+ "version": "1.0.502",
4
4
  "description": "Remote worker agent for Yeaft Web Code Agent — connects the native Yeaft engine, CLI providers, and workbench tools",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -7,6 +7,55 @@ import { resolveAndValidatePath, BINARY_EXTENSIONS } from './utils.js';
7
7
  import { sendWorkbenchResult } from './request-routing.js';
8
8
 
9
9
  export const MAX_WORKBENCH_PREVIEW_BYTES = 20 * 1024 * 1024;
10
+ export const WORKBENCH_FILE_CHUNK_BYTES = 1024 * 1024;
11
+
12
+ async function reportFileTransferDropped(msg, base) {
13
+ const errorResult = {
14
+ ...base,
15
+ type: 'file_content',
16
+ content: '',
17
+ binary: false,
18
+ error: 'File transfer was dropped before it could be delivered.',
19
+ errorCode: 'FILE_TRANSFER_DROPPED',
20
+ };
21
+ return sendWorkbenchResult(ctx, msg, errorResult);
22
+ }
23
+
24
+ async function sendBinaryFile(msg, base, buffer, mimeType) {
25
+ const supportsChunks = ctx.serverCapabilities?.has?.('workbench_file_content_chunks')
26
+ && ctx.agentCapabilities?.includes?.('workbench_file_content_chunks')
27
+ && msg._workbenchRequestId;
28
+ if (!supportsChunks || buffer.length <= WORKBENCH_FILE_CHUNK_BYTES) {
29
+ const outcome = await sendWorkbenchResult(ctx, msg, {
30
+ ...base,
31
+ type: 'file_content',
32
+ content: buffer.toString('base64'),
33
+ binary: true,
34
+ mimeType,
35
+ });
36
+ if (outcome === 'dropped') await reportFileTransferDropped(msg, base);
37
+ return;
38
+ }
39
+
40
+ const chunkCount = Math.ceil(buffer.length / WORKBENCH_FILE_CHUNK_BYTES);
41
+ for (let chunkIndex = 0; chunkIndex < chunkCount; chunkIndex += 1) {
42
+ const start = chunkIndex * WORKBENCH_FILE_CHUNK_BYTES;
43
+ const outcome = await sendWorkbenchResult(ctx, msg, {
44
+ ...base,
45
+ type: 'file_content_chunk',
46
+ binary: true,
47
+ mimeType,
48
+ chunkIndex,
49
+ chunkCount,
50
+ totalBytes: buffer.length,
51
+ content: buffer.subarray(start, start + WORKBENCH_FILE_CHUNK_BYTES).toString('base64'),
52
+ });
53
+ if (outcome === 'dropped') {
54
+ await reportFileTransferDropped(msg, base);
55
+ return;
56
+ }
57
+ }
58
+ }
10
59
 
11
60
  export async function handleReadFile(msg) {
12
61
  const { conversationId, filePath, requestId, _requestUserId, _requestClientId } = msg;
@@ -21,8 +70,8 @@ export async function handleReadFile(msg) {
21
70
 
22
71
  if (mimeType) {
23
72
  const fileStat = await stat(resolved);
24
- if (!msg.download && fileStat.size > MAX_WORKBENCH_PREVIEW_BYTES) {
25
- const error = new Error(`File is too large to preview (${(fileStat.size / 1024 / 1024).toFixed(1)} MB). The preview limit is 20 MB.`);
73
+ if (fileStat.size > MAX_WORKBENCH_PREVIEW_BYTES) {
74
+ const error = new Error(`File is too large to transfer (${(fileStat.size / 1024 / 1024).toFixed(1)} MB). The file limit is 20 MB.`);
26
75
  error.code = 'FILE_PREVIEW_TOO_LARGE';
27
76
  error.details = {
28
77
  sizeBytes: fileStat.size,
@@ -30,22 +79,16 @@ export async function handleReadFile(msg) {
30
79
  };
31
80
  throw error;
32
81
  }
33
- // Binary file: read as Buffer, send base64. Downloads bypass only the
34
- // rendering limit; the WebSocket transport still enforces its own cap.
35
82
  const buffer = await readFile(resolved);
36
83
  console.log('[Agent] Sending binary file_content:', { filePath: resolved, size: buffer.length, mimeType, conversationId });
37
- sendWorkbenchResult(ctx, msg, {
38
- type: 'file_content',
84
+ await sendBinaryFile(msg, {
39
85
  conversationId,
40
86
  requestId,
41
87
  _requestUserId,
42
88
  _requestClientId,
43
89
  filePath: resolved,
44
90
  requestedFilePath: filePath,
45
- content: buffer.toString('base64'),
46
- binary: true,
47
- mimeType
48
- });
91
+ }, buffer, mimeType);
49
92
  } else {
50
93
  // Text file: read as utf-8
51
94
  const content = await readFile(resolved, 'utf-8');
@@ -9,7 +9,7 @@ export function workbenchRequestRouting(source) {
9
9
  }
10
10
 
11
11
  export function sendWorkbenchResult(ctx, request, result) {
12
- ctx.sendToServer({
12
+ return ctx.sendToServer({
13
13
  ...result,
14
14
  ...workbenchRequestRouting(request),
15
15
  });