test-wuying-agentbay-sdk 0.13.0-beta.20251210110535 → 0.13.0-beta.20251210134647
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 +141 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.mjs +140 -22
- package/dist/index.mjs.map +1 -1
- package/docs/api/codespace/code.md +3 -0
- package/docs/examples/codespace/enhanced_code/index.ts +86 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5379,6 +5379,92 @@ var _Code = class _Code {
|
|
|
5379
5379
|
constructor(session) {
|
|
5380
5380
|
this.session = session;
|
|
5381
5381
|
}
|
|
5382
|
+
/**
|
|
5383
|
+
* Parses the backend JSON response into a structured CodeExecutionResult
|
|
5384
|
+
* @param data Raw JSON string from backend
|
|
5385
|
+
*/
|
|
5386
|
+
parseBackendResponse(data) {
|
|
5387
|
+
let raw;
|
|
5388
|
+
try {
|
|
5389
|
+
raw = JSON.parse(data);
|
|
5390
|
+
if (typeof raw === "string") {
|
|
5391
|
+
try {
|
|
5392
|
+
raw = JSON.parse(raw);
|
|
5393
|
+
} catch (e) {
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
} catch (e) {
|
|
5397
|
+
return {
|
|
5398
|
+
requestId: "",
|
|
5399
|
+
// Will be filled later
|
|
5400
|
+
success: true,
|
|
5401
|
+
result: data,
|
|
5402
|
+
logs: { stdout: [data], stderr: [] },
|
|
5403
|
+
results: [{ text: data, isMainResult: true }]
|
|
5404
|
+
};
|
|
5405
|
+
}
|
|
5406
|
+
const logs = {
|
|
5407
|
+
stdout: raw.stdout || [],
|
|
5408
|
+
stderr: raw.stderr || []
|
|
5409
|
+
};
|
|
5410
|
+
const results = [];
|
|
5411
|
+
if (Array.isArray(raw.result)) {
|
|
5412
|
+
for (const itemStr of raw.result) {
|
|
5413
|
+
try {
|
|
5414
|
+
const itemMap = typeof itemStr === "string" ? JSON.parse(itemStr) : itemStr;
|
|
5415
|
+
const item = {};
|
|
5416
|
+
if (itemMap.isMainResult) item.isMainResult = true;
|
|
5417
|
+
if (itemMap.is_main_result) item.isMainResult = true;
|
|
5418
|
+
if (itemMap["text/plain"]) item.text = itemMap["text/plain"];
|
|
5419
|
+
if (itemMap["text/html"]) item.html = itemMap["text/html"];
|
|
5420
|
+
if (itemMap["text/markdown"]) item.markdown = itemMap["text/markdown"];
|
|
5421
|
+
if (itemMap["image/png"]) item.png = itemMap["image/png"];
|
|
5422
|
+
if (itemMap["image/jpeg"]) item.jpeg = itemMap["image/jpeg"];
|
|
5423
|
+
if (itemMap["image/svg+xml"]) item.svg = itemMap["image/svg+xml"];
|
|
5424
|
+
if (itemMap["text/latex"]) item.latex = itemMap["text/latex"];
|
|
5425
|
+
if (itemMap["application/json"]) item.json = itemMap["application/json"];
|
|
5426
|
+
if (itemMap["application/vnd.vegalite.v4+json"]) {
|
|
5427
|
+
item.chart = itemMap["application/vnd.vegalite.v4+json"];
|
|
5428
|
+
} else if (itemMap["application/vnd.vegalite.v5+json"]) {
|
|
5429
|
+
item.chart = itemMap["application/vnd.vegalite.v5+json"];
|
|
5430
|
+
} else if (itemMap["application/vnd.vega.v5+json"]) {
|
|
5431
|
+
item.chart = itemMap["application/vnd.vega.v5+json"];
|
|
5432
|
+
}
|
|
5433
|
+
results.push(item);
|
|
5434
|
+
} catch (e) {
|
|
5435
|
+
}
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
let error;
|
|
5439
|
+
if (raw.executionError) {
|
|
5440
|
+
error = {
|
|
5441
|
+
name: "ExecutionError",
|
|
5442
|
+
value: raw.executionError,
|
|
5443
|
+
traceback: ""
|
|
5444
|
+
};
|
|
5445
|
+
}
|
|
5446
|
+
let resultText = "";
|
|
5447
|
+
const mainRes = results.find((r) => r.isMainResult && r.text);
|
|
5448
|
+
if (mainRes && mainRes.text) {
|
|
5449
|
+
resultText = mainRes.text;
|
|
5450
|
+
} else if (results.length > 0 && results[0].text) {
|
|
5451
|
+
resultText = results[0].text;
|
|
5452
|
+
} else if (logs.stdout.length > 0) {
|
|
5453
|
+
resultText = logs.stdout.join("");
|
|
5454
|
+
}
|
|
5455
|
+
return {
|
|
5456
|
+
requestId: "",
|
|
5457
|
+
// Will be filled by caller
|
|
5458
|
+
success: !raw.executionError,
|
|
5459
|
+
result: resultText,
|
|
5460
|
+
errorMessage: raw.executionError,
|
|
5461
|
+
logs,
|
|
5462
|
+
results,
|
|
5463
|
+
error,
|
|
5464
|
+
executionTime: raw.executionTime || raw.execution_time,
|
|
5465
|
+
executionCount: raw.executionCount || raw.execution_count
|
|
5466
|
+
};
|
|
5467
|
+
}
|
|
5382
5468
|
/**
|
|
5383
5469
|
* Execute code in the specified language with a timeout.
|
|
5384
5470
|
* Corresponds to Python's run_code() method
|
|
@@ -5397,6 +5483,9 @@ var _Code = class _Code {
|
|
|
5397
5483
|
* if (result.success) {
|
|
5398
5484
|
* const codeResult = await result.session.code.runCode('print("Hello")', "python");
|
|
5399
5485
|
* console.log(codeResult.result);
|
|
5486
|
+
* if (codeResult.results) {
|
|
5487
|
+
* // Access rich output like images or charts
|
|
5488
|
+
* }
|
|
5400
5489
|
* await result.session.delete();
|
|
5401
5490
|
* }
|
|
5402
5491
|
* ```
|
|
@@ -5416,23 +5505,34 @@ var _Code = class _Code {
|
|
|
5416
5505
|
language,
|
|
5417
5506
|
timeout_s: timeoutS
|
|
5418
5507
|
};
|
|
5419
|
-
const response = await this.session.callMcpTool(
|
|
5420
|
-
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5508
|
+
const response = await this.session.callMcpTool("run_code", args);
|
|
5509
|
+
let codeResult;
|
|
5510
|
+
if (response.success) {
|
|
5511
|
+
codeResult = this.parseBackendResponse(response.data);
|
|
5512
|
+
} else {
|
|
5513
|
+
try {
|
|
5514
|
+
if (response.errorMessage && response.errorMessage.trim().startsWith("{")) {
|
|
5515
|
+
codeResult = this.parseBackendResponse(response.errorMessage);
|
|
5516
|
+
codeResult.success = false;
|
|
5517
|
+
} else {
|
|
5518
|
+
return {
|
|
5519
|
+
requestId: response.requestId,
|
|
5520
|
+
success: false,
|
|
5521
|
+
result: "",
|
|
5522
|
+
errorMessage: response.errorMessage
|
|
5523
|
+
};
|
|
5524
|
+
}
|
|
5525
|
+
} catch (e6) {
|
|
5526
|
+
return {
|
|
5527
|
+
requestId: response.requestId,
|
|
5528
|
+
success: false,
|
|
5529
|
+
result: "",
|
|
5530
|
+
errorMessage: response.errorMessage
|
|
5531
|
+
};
|
|
5532
|
+
}
|
|
5430
5533
|
}
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
success: true,
|
|
5434
|
-
result: response.data || ""
|
|
5435
|
-
};
|
|
5534
|
+
codeResult.requestId = response.requestId;
|
|
5535
|
+
return codeResult;
|
|
5436
5536
|
} catch (error) {
|
|
5437
5537
|
return {
|
|
5438
5538
|
requestId: "",
|
|
@@ -5610,7 +5710,7 @@ var _Command = class _Command {
|
|
|
5610
5710
|
errorMessage: stderr || result.errorMessage
|
|
5611
5711
|
};
|
|
5612
5712
|
}
|
|
5613
|
-
} catch (
|
|
5713
|
+
} catch (e7) {
|
|
5614
5714
|
}
|
|
5615
5715
|
return {
|
|
5616
5716
|
requestId: result.requestId,
|
|
@@ -10665,6 +10765,12 @@ var _Session = class _Session {
|
|
|
10665
10765
|
if (toolName === "run_code" && actualResult) {
|
|
10666
10766
|
const dataStr = typeof actualResult === "string" ? actualResult : JSON.stringify(actualResult);
|
|
10667
10767
|
logCodeExecutionOutput(requestId, dataStr);
|
|
10768
|
+
return {
|
|
10769
|
+
success: true,
|
|
10770
|
+
data: dataStr,
|
|
10771
|
+
errorMessage: "",
|
|
10772
|
+
requestId: ""
|
|
10773
|
+
};
|
|
10668
10774
|
}
|
|
10669
10775
|
return {
|
|
10670
10776
|
success: true,
|
|
@@ -10699,6 +10805,23 @@ var _Session = class _Session {
|
|
|
10699
10805
|
};
|
|
10700
10806
|
}
|
|
10701
10807
|
const data = response.body.data;
|
|
10808
|
+
const reqId = extractRequestId(response) || "";
|
|
10809
|
+
if (toolName === "run_code") {
|
|
10810
|
+
let dataStr = "";
|
|
10811
|
+
if (data && Array.isArray(data.content) && data.content.length > 0 && data.content[0].text) {
|
|
10812
|
+
dataStr = data.content[0].text;
|
|
10813
|
+
} else {
|
|
10814
|
+
dataStr = typeof response.body.data === "string" ? response.body.data : JSON.stringify(response.body.data);
|
|
10815
|
+
}
|
|
10816
|
+
logCodeExecutionOutput(reqId, dataStr);
|
|
10817
|
+
const isError = data.isError === true;
|
|
10818
|
+
return {
|
|
10819
|
+
success: !isError,
|
|
10820
|
+
data: dataStr,
|
|
10821
|
+
errorMessage: isError ? dataStr : "",
|
|
10822
|
+
requestId: reqId
|
|
10823
|
+
};
|
|
10824
|
+
}
|
|
10702
10825
|
if (data.isError) {
|
|
10703
10826
|
const errorContent = data.content || [];
|
|
10704
10827
|
const errorMessage = errorContent.map((item) => item.text || "Unknown error").join("; ");
|
|
@@ -10706,7 +10829,7 @@ var _Session = class _Session {
|
|
|
10706
10829
|
success: false,
|
|
10707
10830
|
data: "",
|
|
10708
10831
|
errorMessage,
|
|
10709
|
-
requestId:
|
|
10832
|
+
requestId: reqId
|
|
10710
10833
|
};
|
|
10711
10834
|
}
|
|
10712
10835
|
const content = data.content || [];
|
|
@@ -10714,11 +10837,6 @@ var _Session = class _Session {
|
|
|
10714
10837
|
if (content.length > 0 && content[0].text !== void 0) {
|
|
10715
10838
|
textContent = content[0].text;
|
|
10716
10839
|
}
|
|
10717
|
-
const reqId = extractRequestId(response) || "";
|
|
10718
|
-
if (toolName === "run_code" && data) {
|
|
10719
|
-
const dataStr = typeof response.body.data === "string" ? response.body.data : JSON.stringify(response.body.data);
|
|
10720
|
-
logCodeExecutionOutput(reqId, dataStr);
|
|
10721
|
-
}
|
|
10722
10840
|
return {
|
|
10723
10841
|
success: true,
|
|
10724
10842
|
data: textContent,
|