test-wuying-agentbay-sdk 0.13.1-beta.20251224091333 → 0.13.1-beta.20251224100120
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/dist/index.cjs +375 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +88 -12
- package/dist/index.d.ts +88 -12
- package/dist/index.mjs +331 -114
- package/dist/index.mjs.map +1 -1
- package/docs/api/common-features/basics/filesystem.md +57 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2325,11 +2325,20 @@ var LOG_LEVEL_VALUES = {
|
|
|
2325
2325
|
};
|
|
2326
2326
|
var currentRequestId = "";
|
|
2327
2327
|
var currentLogLevel = process.env.LOG_LEVEL || process.env.AGENTBAY_LOG_LEVEL || "INFO";
|
|
2328
|
+
var currentLogFormat = process.env.AGENTBAY_LOG_FORMAT || "pretty";
|
|
2329
|
+
if (["sls", "compact"].includes(String(currentLogFormat).toLowerCase())) {
|
|
2330
|
+
currentLogFormat = "sls";
|
|
2331
|
+
} else {
|
|
2332
|
+
currentLogFormat = "pretty";
|
|
2333
|
+
}
|
|
2328
2334
|
var fileLoggingEnabled = false;
|
|
2329
2335
|
var logFilePath = null;
|
|
2330
2336
|
var logFileMaxSize = 10 * 1024 * 1024;
|
|
2331
2337
|
var consoleLoggingEnabled = true;
|
|
2332
2338
|
function shouldUseColors() {
|
|
2339
|
+
if (currentLogFormat === "sls") {
|
|
2340
|
+
return false;
|
|
2341
|
+
}
|
|
2333
2342
|
if (process.env.DISABLE_COLORS === "true") {
|
|
2334
2343
|
return false;
|
|
2335
2344
|
}
|
|
@@ -2371,6 +2380,9 @@ var SENSITIVE_FIELDS = [
|
|
|
2371
2380
|
"authorization"
|
|
2372
2381
|
];
|
|
2373
2382
|
function getLogLevelEmoji(level) {
|
|
2383
|
+
if (currentLogFormat === "sls") {
|
|
2384
|
+
return level;
|
|
2385
|
+
}
|
|
2374
2386
|
switch (level) {
|
|
2375
2387
|
case "DEBUG":
|
|
2376
2388
|
return "\u{1F41B} DEBUG";
|
|
@@ -2390,6 +2402,13 @@ function shouldLog(level) {
|
|
|
2390
2402
|
}
|
|
2391
2403
|
__name(shouldLog, "shouldLog");
|
|
2392
2404
|
function formatLogMessage(level, message, forFile = false) {
|
|
2405
|
+
if (currentLogFormat === "sls") {
|
|
2406
|
+
let formattedMessage2 = `${level}: ${message}`;
|
|
2407
|
+
if (currentRequestId) {
|
|
2408
|
+
formattedMessage2 += ` [RequestId=${currentRequestId}]`;
|
|
2409
|
+
}
|
|
2410
|
+
return formattedMessage2;
|
|
2411
|
+
}
|
|
2393
2412
|
let formattedMessage = `${getLogLevelEmoji(level)}: ${message}`;
|
|
2394
2413
|
if (currentRequestId) {
|
|
2395
2414
|
formattedMessage += ` [RequestId=${currentRequestId}]`;
|
|
@@ -2537,6 +2556,23 @@ function setupLogger(config) {
|
|
|
2537
2556
|
if (config.enableConsole !== void 0) {
|
|
2538
2557
|
consoleLoggingEnabled = config.enableConsole;
|
|
2539
2558
|
}
|
|
2559
|
+
if (config.format) {
|
|
2560
|
+
if (["sls", "compact"].includes(String(config.format).toLowerCase())) {
|
|
2561
|
+
currentLogFormat = "sls";
|
|
2562
|
+
} else {
|
|
2563
|
+
currentLogFormat = "pretty";
|
|
2564
|
+
}
|
|
2565
|
+
} else {
|
|
2566
|
+
const envFormat = process.env.AGENTBAY_LOG_FORMAT;
|
|
2567
|
+
if (envFormat) {
|
|
2568
|
+
if (["sls", "compact"].includes(String(envFormat).toLowerCase())) {
|
|
2569
|
+
currentLogFormat = "sls";
|
|
2570
|
+
} else {
|
|
2571
|
+
currentLogFormat = "pretty";
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
useColors = shouldUseColors();
|
|
2540
2576
|
}
|
|
2541
2577
|
__name(setupLogger, "setupLogger");
|
|
2542
2578
|
function log(message, ...args) {
|
|
@@ -2644,6 +2680,22 @@ ${error.stack}`;
|
|
|
2644
2680
|
__name(logError, "logError");
|
|
2645
2681
|
function logAPICall(apiName, requestData) {
|
|
2646
2682
|
if (!shouldLog("INFO")) return;
|
|
2683
|
+
if (currentLogFormat === "sls") {
|
|
2684
|
+
let message2 = `API Call: ${apiName}`;
|
|
2685
|
+
if (requestData) {
|
|
2686
|
+
const maskedData = maskSensitiveData(requestData);
|
|
2687
|
+
if (typeof maskedData === "string") {
|
|
2688
|
+
message2 += `, ${maskedData}`;
|
|
2689
|
+
} else {
|
|
2690
|
+
message2 += `, ${JSON.stringify(maskedData)}`;
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
if (consoleLoggingEnabled) {
|
|
2694
|
+
process.stdout.write(message2 + "\n");
|
|
2695
|
+
}
|
|
2696
|
+
writeToFile(message2);
|
|
2697
|
+
return;
|
|
2698
|
+
}
|
|
2647
2699
|
const message = `\u{1F517} API Call: ${apiName}`;
|
|
2648
2700
|
const savedRequestId = currentRequestId;
|
|
2649
2701
|
currentRequestId = "";
|
|
@@ -2661,6 +2713,35 @@ function logAPICall(apiName, requestData) {
|
|
|
2661
2713
|
}
|
|
2662
2714
|
__name(logAPICall, "logAPICall");
|
|
2663
2715
|
function logAPIResponseWithDetails(apiName, requestId, success = true, keyFields, fullResponse) {
|
|
2716
|
+
if (currentLogFormat === "sls") {
|
|
2717
|
+
if (!shouldLog(success ? "INFO" : "ERROR")) return;
|
|
2718
|
+
const status = success ? "API Response" : "API Response Failed";
|
|
2719
|
+
let msg = `${status}: ${apiName}`;
|
|
2720
|
+
if (requestId) {
|
|
2721
|
+
msg += `, RequestId=${requestId}`;
|
|
2722
|
+
}
|
|
2723
|
+
if (keyFields) {
|
|
2724
|
+
for (const [key, value] of Object.entries(keyFields)) {
|
|
2725
|
+
const maskedValue = maskSensitiveData({ [key]: value });
|
|
2726
|
+
msg += `, ${key}=${maskedValue[key]}`;
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
if (success) {
|
|
2730
|
+
if (consoleLoggingEnabled) {
|
|
2731
|
+
process.stdout.write(msg + "\n");
|
|
2732
|
+
}
|
|
2733
|
+
writeToFile(msg);
|
|
2734
|
+
} else {
|
|
2735
|
+
if (consoleLoggingEnabled) {
|
|
2736
|
+
process.stderr.write(msg + "\n");
|
|
2737
|
+
}
|
|
2738
|
+
writeToFile(msg);
|
|
2739
|
+
}
|
|
2740
|
+
if (fullResponse && shouldLog("DEBUG")) {
|
|
2741
|
+
logDebug(`Full Response: ${fullResponse}`);
|
|
2742
|
+
}
|
|
2743
|
+
return;
|
|
2744
|
+
}
|
|
2664
2745
|
if (success) {
|
|
2665
2746
|
if (shouldLog("INFO")) {
|
|
2666
2747
|
let mainMessage = `\u2705 API Response: ${apiName}`;
|
|
@@ -2732,6 +2813,16 @@ function logCodeExecutionOutput(requestId, rawOutput) {
|
|
|
2732
2813
|
return;
|
|
2733
2814
|
}
|
|
2734
2815
|
const actualOutput = texts.join("");
|
|
2816
|
+
if (currentLogFormat === "sls") {
|
|
2817
|
+
const header2 = `Code Execution Output (RequestID: ${requestId}):`;
|
|
2818
|
+
if (consoleLoggingEnabled) {
|
|
2819
|
+
process.stdout.write(header2 + "\n");
|
|
2820
|
+
process.stdout.write(actualOutput + "\n");
|
|
2821
|
+
}
|
|
2822
|
+
writeToFile(header2);
|
|
2823
|
+
writeToFile(actualOutput);
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2735
2826
|
const header = `\u{1F4CB} Code Execution Output (RequestID: ${requestId}):`;
|
|
2736
2827
|
if (useColors) {
|
|
2737
2828
|
process.stdout.write(`${ANSI_GREEN}\u2139\uFE0F INFO: ${header}${ANSI_RESET}
|
|
@@ -2761,6 +2852,10 @@ function logCodeExecutionOutput(requestId, rawOutput) {
|
|
|
2761
2852
|
__name(logCodeExecutionOutput, "logCodeExecutionOutput");
|
|
2762
2853
|
function logInfoWithColor(message, color = ANSI_RED) {
|
|
2763
2854
|
if (!shouldLog("INFO")) return;
|
|
2855
|
+
if (currentLogFormat === "sls") {
|
|
2856
|
+
logInfo(message);
|
|
2857
|
+
return;
|
|
2858
|
+
}
|
|
2764
2859
|
const emoji = "\u2139\uFE0F INFO";
|
|
2765
2860
|
const fullMessage = `${emoji}: ${message}`;
|
|
2766
2861
|
if (useColors) {
|
|
@@ -14227,43 +14322,107 @@ var _FileSystem = class _FileSystem {
|
|
|
14227
14322
|
* @param path - Path to the file to read.
|
|
14228
14323
|
* @param offset - Optional: Byte offset to start reading from (0-based).
|
|
14229
14324
|
* @param length - Optional: Number of bytes to read. If 0, reads the entire file from offset.
|
|
14230
|
-
* @
|
|
14325
|
+
* @param formatType - Optional: Format to read the file in. "text" (default) or "binary".
|
|
14326
|
+
* @returns FileContentResult for text format, BinaryFileContentResult for binary format
|
|
14231
14327
|
*/
|
|
14232
|
-
async readFileChunk(path6, offset = 0, length = 0) {
|
|
14328
|
+
async readFileChunk(path6, offset = 0, length = 0, formatType = "text") {
|
|
14233
14329
|
try {
|
|
14234
14330
|
const args = {
|
|
14235
14331
|
path: path6
|
|
14236
14332
|
};
|
|
14237
|
-
if (offset
|
|
14333
|
+
if (offset >= 0) {
|
|
14238
14334
|
args.offset = offset;
|
|
14239
14335
|
}
|
|
14240
|
-
if (length
|
|
14336
|
+
if (length >= 0) {
|
|
14241
14337
|
args.length = length;
|
|
14242
14338
|
}
|
|
14339
|
+
if (formatType === "binary") {
|
|
14340
|
+
args.format = "binary";
|
|
14341
|
+
}
|
|
14243
14342
|
const result = await this.session.callMcpTool(
|
|
14244
14343
|
"read_file",
|
|
14245
14344
|
args
|
|
14246
14345
|
);
|
|
14247
14346
|
if (!result.success) {
|
|
14347
|
+
if (formatType === "binary") {
|
|
14348
|
+
return {
|
|
14349
|
+
requestId: result.requestId,
|
|
14350
|
+
success: false,
|
|
14351
|
+
content: new Uint8Array(0),
|
|
14352
|
+
errorMessage: result.errorMessage
|
|
14353
|
+
};
|
|
14354
|
+
} else {
|
|
14355
|
+
return {
|
|
14356
|
+
requestId: result.requestId,
|
|
14357
|
+
success: false,
|
|
14358
|
+
content: "",
|
|
14359
|
+
errorMessage: result.errorMessage
|
|
14360
|
+
};
|
|
14361
|
+
}
|
|
14362
|
+
}
|
|
14363
|
+
if (formatType === "binary") {
|
|
14364
|
+
try {
|
|
14365
|
+
if (typeof Buffer !== "undefined") {
|
|
14366
|
+
const base64String = result.data || "";
|
|
14367
|
+
if (base64String) {
|
|
14368
|
+
const base64WithoutPadding = base64String.replace(/=+$/, "");
|
|
14369
|
+
if (!/^[A-Za-z0-9+/]+$/.test(base64WithoutPadding)) {
|
|
14370
|
+
throw new Error("Invalid base64 string format");
|
|
14371
|
+
}
|
|
14372
|
+
const paddingMatch = base64String.match(/=+$/);
|
|
14373
|
+
if (paddingMatch && paddingMatch[0].length > 2) {
|
|
14374
|
+
throw new Error("Invalid base64 padding format");
|
|
14375
|
+
}
|
|
14376
|
+
}
|
|
14377
|
+
const binaryContent = Buffer.from(base64String, "base64");
|
|
14378
|
+
return {
|
|
14379
|
+
requestId: result.requestId,
|
|
14380
|
+
success: true,
|
|
14381
|
+
content: new Uint8Array(binaryContent)
|
|
14382
|
+
};
|
|
14383
|
+
} else {
|
|
14384
|
+
const binaryString = atob(result.data || "");
|
|
14385
|
+
const binaryContent = new Uint8Array(binaryString.length);
|
|
14386
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
14387
|
+
binaryContent[i] = binaryString.charCodeAt(i);
|
|
14388
|
+
}
|
|
14389
|
+
return {
|
|
14390
|
+
requestId: result.requestId,
|
|
14391
|
+
success: true,
|
|
14392
|
+
content: binaryContent
|
|
14393
|
+
};
|
|
14394
|
+
}
|
|
14395
|
+
} catch (e) {
|
|
14396
|
+
return {
|
|
14397
|
+
requestId: result.requestId,
|
|
14398
|
+
success: false,
|
|
14399
|
+
content: new Uint8Array(0),
|
|
14400
|
+
errorMessage: `Failed to decode base64: ${e}`
|
|
14401
|
+
};
|
|
14402
|
+
}
|
|
14403
|
+
} else {
|
|
14248
14404
|
return {
|
|
14249
14405
|
requestId: result.requestId,
|
|
14406
|
+
success: true,
|
|
14407
|
+
content: result.data || ""
|
|
14408
|
+
};
|
|
14409
|
+
}
|
|
14410
|
+
} catch (error) {
|
|
14411
|
+
if (formatType === "binary") {
|
|
14412
|
+
return {
|
|
14413
|
+
requestId: "",
|
|
14414
|
+
success: false,
|
|
14415
|
+
content: new Uint8Array(0),
|
|
14416
|
+
errorMessage: `Failed to read file: ${error}`
|
|
14417
|
+
};
|
|
14418
|
+
} else {
|
|
14419
|
+
return {
|
|
14420
|
+
requestId: "",
|
|
14250
14421
|
success: false,
|
|
14251
14422
|
content: "",
|
|
14252
|
-
errorMessage:
|
|
14423
|
+
errorMessage: `Failed to read file: ${error}`
|
|
14253
14424
|
};
|
|
14254
14425
|
}
|
|
14255
|
-
return {
|
|
14256
|
-
requestId: result.requestId,
|
|
14257
|
-
success: true,
|
|
14258
|
-
content: result.data || ""
|
|
14259
|
-
};
|
|
14260
|
-
} catch (error) {
|
|
14261
|
-
return {
|
|
14262
|
-
requestId: "",
|
|
14263
|
-
success: false,
|
|
14264
|
-
content: "",
|
|
14265
|
-
errorMessage: `Failed to read file: ${error}`
|
|
14266
|
-
};
|
|
14267
14426
|
}
|
|
14268
14427
|
}
|
|
14269
14428
|
/**
|
|
@@ -14461,120 +14620,178 @@ var _FileSystem = class _FileSystem {
|
|
|
14461
14620
|
};
|
|
14462
14621
|
}
|
|
14463
14622
|
}
|
|
14464
|
-
|
|
14465
|
-
|
|
14466
|
-
*
|
|
14467
|
-
* @param path - Path to the file to read.
|
|
14468
|
-
* @returns FileContentResult with complete file content and requestId
|
|
14469
|
-
*/
|
|
14470
|
-
/**
|
|
14471
|
-
* Reads the entire content of a file.
|
|
14472
|
-
*
|
|
14473
|
-
* @param path - Absolute path to the file to read.
|
|
14474
|
-
*
|
|
14475
|
-
* @returns Promise resolving to FileContentResult containing:
|
|
14476
|
-
* - success: Whether the read operation succeeded
|
|
14477
|
-
* - content: String content of the file
|
|
14478
|
-
* - requestId: Unique identifier for this API request
|
|
14479
|
-
* - errorMessage: Error description if read failed
|
|
14480
|
-
*
|
|
14481
|
-
* @throws Error if the API call fails.
|
|
14482
|
-
*
|
|
14483
|
-
* @example
|
|
14484
|
-
* ```typescript
|
|
14485
|
-
* import { AgentBay } from 'wuying-agentbay-sdk';
|
|
14486
|
-
*
|
|
14487
|
-
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
14488
|
-
* const result = await agentBay.create();
|
|
14489
|
-
*
|
|
14490
|
-
* if (result.success) {
|
|
14491
|
-
* const session = result.session;
|
|
14492
|
-
*
|
|
14493
|
-
* // Read a text file
|
|
14494
|
-
* const fileResult = await session.fileSystem.readFile('/etc/hostname');
|
|
14495
|
-
* if (fileResult.success) {
|
|
14496
|
-
* console.log(`Content: ${fileResult.content}`);
|
|
14497
|
-
* // Output: Content: agentbay-session-xyz
|
|
14498
|
-
* }
|
|
14499
|
-
*
|
|
14500
|
-
* await session.delete();
|
|
14501
|
-
* }
|
|
14502
|
-
* ```
|
|
14503
|
-
*
|
|
14504
|
-
* @remarks
|
|
14505
|
-
* **Behavior:**
|
|
14506
|
-
* - Automatically handles large files by reading in 60KB chunks
|
|
14507
|
-
* - Returns empty string for empty files
|
|
14508
|
-
* - Fails if path is a directory or doesn't exist
|
|
14509
|
-
* - Content is returned as UTF-8 string
|
|
14510
|
-
*
|
|
14511
|
-
* @see {@link writeFile}, {@link listDirectory}
|
|
14512
|
-
*/
|
|
14513
|
-
async readFile(path6) {
|
|
14623
|
+
async readFile(path6, opts) {
|
|
14624
|
+
const format = opts?.format || "text";
|
|
14514
14625
|
const chunkSize = DEFAULT_CHUNK_SIZE;
|
|
14515
14626
|
try {
|
|
14516
14627
|
const fileInfoResult = await this.getFileInfo(path6);
|
|
14517
14628
|
if (!fileInfoResult.success) {
|
|
14518
|
-
|
|
14519
|
-
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14629
|
+
if (format === "bytes") {
|
|
14630
|
+
return {
|
|
14631
|
+
requestId: fileInfoResult.requestId,
|
|
14632
|
+
success: false,
|
|
14633
|
+
content: new Uint8Array(0),
|
|
14634
|
+
errorMessage: fileInfoResult.errorMessage
|
|
14635
|
+
};
|
|
14636
|
+
} else {
|
|
14637
|
+
return {
|
|
14638
|
+
requestId: fileInfoResult.requestId,
|
|
14639
|
+
success: false,
|
|
14640
|
+
content: "",
|
|
14641
|
+
errorMessage: fileInfoResult.errorMessage
|
|
14642
|
+
};
|
|
14643
|
+
}
|
|
14524
14644
|
}
|
|
14525
14645
|
if (!fileInfoResult.fileInfo || fileInfoResult.fileInfo.isDirectory) {
|
|
14526
|
-
|
|
14527
|
-
|
|
14528
|
-
|
|
14529
|
-
|
|
14530
|
-
|
|
14531
|
-
|
|
14646
|
+
const errorMsg = `Path does not exist or is a directory: ${path6}`;
|
|
14647
|
+
if (format === "bytes") {
|
|
14648
|
+
return {
|
|
14649
|
+
requestId: fileInfoResult.requestId,
|
|
14650
|
+
success: false,
|
|
14651
|
+
content: new Uint8Array(0),
|
|
14652
|
+
errorMessage: errorMsg
|
|
14653
|
+
};
|
|
14654
|
+
} else {
|
|
14655
|
+
return {
|
|
14656
|
+
requestId: fileInfoResult.requestId,
|
|
14657
|
+
success: false,
|
|
14658
|
+
content: "",
|
|
14659
|
+
errorMessage: errorMsg
|
|
14660
|
+
};
|
|
14661
|
+
}
|
|
14532
14662
|
}
|
|
14533
14663
|
const fileSize = fileInfoResult.fileInfo.size || 0;
|
|
14534
14664
|
if (fileSize === 0) {
|
|
14665
|
+
if (format === "bytes") {
|
|
14666
|
+
return {
|
|
14667
|
+
requestId: fileInfoResult.requestId,
|
|
14668
|
+
success: true,
|
|
14669
|
+
content: new Uint8Array(0),
|
|
14670
|
+
size: 0
|
|
14671
|
+
};
|
|
14672
|
+
} else {
|
|
14673
|
+
return {
|
|
14674
|
+
requestId: fileInfoResult.requestId,
|
|
14675
|
+
success: true,
|
|
14676
|
+
content: ""
|
|
14677
|
+
};
|
|
14678
|
+
}
|
|
14679
|
+
}
|
|
14680
|
+
if (format === "bytes") {
|
|
14681
|
+
const contentChunks = [];
|
|
14682
|
+
let offset = 0;
|
|
14683
|
+
let chunkCount = 0;
|
|
14684
|
+
while (offset < fileSize) {
|
|
14685
|
+
let length = chunkSize;
|
|
14686
|
+
if (offset + length > fileSize) {
|
|
14687
|
+
length = fileSize - offset;
|
|
14688
|
+
}
|
|
14689
|
+
try {
|
|
14690
|
+
const chunkResult = await this.readFileChunk(
|
|
14691
|
+
path6,
|
|
14692
|
+
offset,
|
|
14693
|
+
length,
|
|
14694
|
+
"binary"
|
|
14695
|
+
);
|
|
14696
|
+
if (!chunkResult.success) {
|
|
14697
|
+
return chunkResult;
|
|
14698
|
+
}
|
|
14699
|
+
if ("content" in chunkResult && chunkResult.content instanceof Uint8Array) {
|
|
14700
|
+
contentChunks.push(chunkResult.content);
|
|
14701
|
+
} else {
|
|
14702
|
+
return {
|
|
14703
|
+
requestId: chunkResult.requestId,
|
|
14704
|
+
success: false,
|
|
14705
|
+
content: new Uint8Array(0),
|
|
14706
|
+
errorMessage: "Unexpected result type for binary format"
|
|
14707
|
+
};
|
|
14708
|
+
}
|
|
14709
|
+
offset += length;
|
|
14710
|
+
chunkCount++;
|
|
14711
|
+
} catch (error) {
|
|
14712
|
+
return {
|
|
14713
|
+
requestId: fileInfoResult.requestId,
|
|
14714
|
+
success: false,
|
|
14715
|
+
content: new Uint8Array(0),
|
|
14716
|
+
errorMessage: `Error reading chunk at offset ${offset}: ${error}`
|
|
14717
|
+
};
|
|
14718
|
+
}
|
|
14719
|
+
}
|
|
14720
|
+
const totalLength = contentChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
14721
|
+
const finalContent = new Uint8Array(totalLength);
|
|
14722
|
+
let position = 0;
|
|
14723
|
+
for (const chunk of contentChunks) {
|
|
14724
|
+
finalContent.set(chunk, position);
|
|
14725
|
+
position += chunk.length;
|
|
14726
|
+
}
|
|
14535
14727
|
return {
|
|
14536
14728
|
requestId: fileInfoResult.requestId,
|
|
14537
14729
|
success: true,
|
|
14538
|
-
content:
|
|
14730
|
+
content: finalContent,
|
|
14731
|
+
size: finalContent.length
|
|
14539
14732
|
};
|
|
14540
|
-
}
|
|
14541
|
-
|
|
14542
|
-
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
|
|
14546
|
-
|
|
14547
|
-
|
|
14548
|
-
|
|
14549
|
-
|
|
14550
|
-
|
|
14551
|
-
|
|
14552
|
-
|
|
14733
|
+
} else {
|
|
14734
|
+
let result = "";
|
|
14735
|
+
let offset = 0;
|
|
14736
|
+
let chunkCount = 0;
|
|
14737
|
+
while (offset < fileSize) {
|
|
14738
|
+
let length = chunkSize;
|
|
14739
|
+
if (offset + length > fileSize) {
|
|
14740
|
+
length = fileSize - offset;
|
|
14741
|
+
}
|
|
14742
|
+
try {
|
|
14743
|
+
const chunkResult = await this.readFileChunk(
|
|
14744
|
+
path6,
|
|
14745
|
+
offset,
|
|
14746
|
+
length,
|
|
14747
|
+
"text"
|
|
14748
|
+
);
|
|
14749
|
+
if (!chunkResult.success) {
|
|
14750
|
+
return chunkResult;
|
|
14751
|
+
}
|
|
14752
|
+
if ("content" in chunkResult && typeof chunkResult.content === "string") {
|
|
14753
|
+
result += chunkResult.content;
|
|
14754
|
+
} else {
|
|
14755
|
+
return {
|
|
14756
|
+
requestId: chunkResult.requestId,
|
|
14757
|
+
success: false,
|
|
14758
|
+
content: "",
|
|
14759
|
+
errorMessage: "Unexpected result type for text format"
|
|
14760
|
+
};
|
|
14761
|
+
}
|
|
14762
|
+
offset += length;
|
|
14763
|
+
chunkCount++;
|
|
14764
|
+
} catch (error) {
|
|
14765
|
+
return {
|
|
14766
|
+
requestId: fileInfoResult.requestId,
|
|
14767
|
+
success: false,
|
|
14768
|
+
content: "",
|
|
14769
|
+
errorMessage: `Error reading chunk at offset ${offset}: ${error}`
|
|
14770
|
+
};
|
|
14553
14771
|
}
|
|
14554
|
-
result += chunkResult.content;
|
|
14555
|
-
offset += length;
|
|
14556
|
-
chunkCount++;
|
|
14557
|
-
} catch (error) {
|
|
14558
|
-
return {
|
|
14559
|
-
requestId: fileInfoResult.requestId,
|
|
14560
|
-
success: false,
|
|
14561
|
-
content: "",
|
|
14562
|
-
errorMessage: `Error reading chunk at offset ${offset}: ${error}`
|
|
14563
|
-
};
|
|
14564
14772
|
}
|
|
14773
|
+
return {
|
|
14774
|
+
requestId: fileInfoResult.requestId,
|
|
14775
|
+
success: true,
|
|
14776
|
+
content: result
|
|
14777
|
+
};
|
|
14565
14778
|
}
|
|
14566
|
-
return {
|
|
14567
|
-
requestId: fileInfoResult.requestId,
|
|
14568
|
-
success: true,
|
|
14569
|
-
content: result
|
|
14570
|
-
};
|
|
14571
14779
|
} catch (error) {
|
|
14572
|
-
|
|
14573
|
-
|
|
14574
|
-
|
|
14575
|
-
|
|
14576
|
-
|
|
14577
|
-
|
|
14780
|
+
if (format === "bytes") {
|
|
14781
|
+
return {
|
|
14782
|
+
requestId: "",
|
|
14783
|
+
success: false,
|
|
14784
|
+
content: new Uint8Array(0),
|
|
14785
|
+
errorMessage: `Failed to read large file: ${error}`
|
|
14786
|
+
};
|
|
14787
|
+
} else {
|
|
14788
|
+
return {
|
|
14789
|
+
requestId: "",
|
|
14790
|
+
success: false,
|
|
14791
|
+
content: "",
|
|
14792
|
+
errorMessage: `Failed to read large file: ${error}`
|
|
14793
|
+
};
|
|
14794
|
+
}
|
|
14578
14795
|
}
|
|
14579
14796
|
}
|
|
14580
14797
|
/**
|