test-wuying-agentbay-sdk 0.13.0-beta.20251210113609 → 0.13.0-beta.20251210135226
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.d.mts
CHANGED
|
@@ -146,19 +146,55 @@ interface CommandResult extends ApiResponse {
|
|
|
146
146
|
/** Trace ID for error tracking. Only present when errorCode != 0. Used for quick problem localization. */
|
|
147
147
|
traceId?: string;
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Interface for single result item in enhanced code execution
|
|
151
|
+
*/
|
|
152
|
+
interface CodeExecutionResultItem {
|
|
153
|
+
text?: string;
|
|
154
|
+
html?: string;
|
|
155
|
+
markdown?: string;
|
|
156
|
+
png?: string;
|
|
157
|
+
jpeg?: string;
|
|
158
|
+
svg?: string;
|
|
159
|
+
latex?: string;
|
|
160
|
+
json?: any;
|
|
161
|
+
chart?: any;
|
|
162
|
+
isMainResult?: boolean;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Interface for code execution logs
|
|
166
|
+
*/
|
|
167
|
+
interface CodeExecutionLogs {
|
|
168
|
+
stdout: string[];
|
|
169
|
+
stderr: string[];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Interface for code execution error details
|
|
173
|
+
*/
|
|
174
|
+
interface CodeExecutionError {
|
|
175
|
+
name: string;
|
|
176
|
+
value: string;
|
|
177
|
+
traceback: string;
|
|
178
|
+
}
|
|
149
179
|
/**
|
|
150
180
|
* Interface for code execution operation responses
|
|
151
|
-
* Corresponds to Python's
|
|
181
|
+
* Corresponds to Python's EnhancedCodeExecutionResult type
|
|
152
182
|
*/
|
|
153
183
|
interface CodeExecutionResult extends ApiResponse {
|
|
154
184
|
/** Request identifier for tracking API calls */
|
|
155
185
|
requestId: string;
|
|
156
186
|
/** Whether the code execution was successful */
|
|
157
187
|
success: boolean;
|
|
158
|
-
/** The execution result */
|
|
188
|
+
/** The execution result (backward compatible text) */
|
|
159
189
|
result: string;
|
|
160
190
|
/** Optional error message if the operation failed */
|
|
161
191
|
errorMessage?: string;
|
|
192
|
+
/** Enhanced fields */
|
|
193
|
+
logs?: CodeExecutionLogs;
|
|
194
|
+
results?: CodeExecutionResultItem[];
|
|
195
|
+
error?: CodeExecutionError;
|
|
196
|
+
executionTime?: number;
|
|
197
|
+
executionCount?: number;
|
|
162
198
|
}
|
|
163
199
|
/**
|
|
164
200
|
* Interface for boolean operation responses
|
|
@@ -3651,6 +3687,11 @@ declare class Code {
|
|
|
3651
3687
|
requestId: string;
|
|
3652
3688
|
}>;
|
|
3653
3689
|
});
|
|
3690
|
+
/**
|
|
3691
|
+
* Parses the backend JSON response into a structured CodeExecutionResult
|
|
3692
|
+
* @param data Raw JSON string from backend
|
|
3693
|
+
*/
|
|
3694
|
+
private parseBackendResponse;
|
|
3654
3695
|
/**
|
|
3655
3696
|
* Execute code in the specified language with a timeout.
|
|
3656
3697
|
* Corresponds to Python's run_code() method
|
|
@@ -3669,6 +3710,9 @@ declare class Code {
|
|
|
3669
3710
|
* if (result.success) {
|
|
3670
3711
|
* const codeResult = await result.session.code.runCode('print("Hello")', "python");
|
|
3671
3712
|
* console.log(codeResult.result);
|
|
3713
|
+
* if (codeResult.results) {
|
|
3714
|
+
* // Access rich output like images or charts
|
|
3715
|
+
* }
|
|
3672
3716
|
* await result.session.delete();
|
|
3673
3717
|
* }
|
|
3674
3718
|
* ```
|
package/dist/index.d.ts
CHANGED
|
@@ -146,19 +146,55 @@ interface CommandResult extends ApiResponse {
|
|
|
146
146
|
/** Trace ID for error tracking. Only present when errorCode != 0. Used for quick problem localization. */
|
|
147
147
|
traceId?: string;
|
|
148
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Interface for single result item in enhanced code execution
|
|
151
|
+
*/
|
|
152
|
+
interface CodeExecutionResultItem {
|
|
153
|
+
text?: string;
|
|
154
|
+
html?: string;
|
|
155
|
+
markdown?: string;
|
|
156
|
+
png?: string;
|
|
157
|
+
jpeg?: string;
|
|
158
|
+
svg?: string;
|
|
159
|
+
latex?: string;
|
|
160
|
+
json?: any;
|
|
161
|
+
chart?: any;
|
|
162
|
+
isMainResult?: boolean;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Interface for code execution logs
|
|
166
|
+
*/
|
|
167
|
+
interface CodeExecutionLogs {
|
|
168
|
+
stdout: string[];
|
|
169
|
+
stderr: string[];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Interface for code execution error details
|
|
173
|
+
*/
|
|
174
|
+
interface CodeExecutionError {
|
|
175
|
+
name: string;
|
|
176
|
+
value: string;
|
|
177
|
+
traceback: string;
|
|
178
|
+
}
|
|
149
179
|
/**
|
|
150
180
|
* Interface for code execution operation responses
|
|
151
|
-
* Corresponds to Python's
|
|
181
|
+
* Corresponds to Python's EnhancedCodeExecutionResult type
|
|
152
182
|
*/
|
|
153
183
|
interface CodeExecutionResult extends ApiResponse {
|
|
154
184
|
/** Request identifier for tracking API calls */
|
|
155
185
|
requestId: string;
|
|
156
186
|
/** Whether the code execution was successful */
|
|
157
187
|
success: boolean;
|
|
158
|
-
/** The execution result */
|
|
188
|
+
/** The execution result (backward compatible text) */
|
|
159
189
|
result: string;
|
|
160
190
|
/** Optional error message if the operation failed */
|
|
161
191
|
errorMessage?: string;
|
|
192
|
+
/** Enhanced fields */
|
|
193
|
+
logs?: CodeExecutionLogs;
|
|
194
|
+
results?: CodeExecutionResultItem[];
|
|
195
|
+
error?: CodeExecutionError;
|
|
196
|
+
executionTime?: number;
|
|
197
|
+
executionCount?: number;
|
|
162
198
|
}
|
|
163
199
|
/**
|
|
164
200
|
* Interface for boolean operation responses
|
|
@@ -3651,6 +3687,11 @@ declare class Code {
|
|
|
3651
3687
|
requestId: string;
|
|
3652
3688
|
}>;
|
|
3653
3689
|
});
|
|
3690
|
+
/**
|
|
3691
|
+
* Parses the backend JSON response into a structured CodeExecutionResult
|
|
3692
|
+
* @param data Raw JSON string from backend
|
|
3693
|
+
*/
|
|
3694
|
+
private parseBackendResponse;
|
|
3654
3695
|
/**
|
|
3655
3696
|
* Execute code in the specified language with a timeout.
|
|
3656
3697
|
* Corresponds to Python's run_code() method
|
|
@@ -3669,6 +3710,9 @@ declare class Code {
|
|
|
3669
3710
|
* if (result.success) {
|
|
3670
3711
|
* const codeResult = await result.session.code.runCode('print("Hello")', "python");
|
|
3671
3712
|
* console.log(codeResult.result);
|
|
3713
|
+
* if (codeResult.results) {
|
|
3714
|
+
* // Access rich output like images or charts
|
|
3715
|
+
* }
|
|
3672
3716
|
* await result.session.delete();
|
|
3673
3717
|
* }
|
|
3674
3718
|
* ```
|
package/dist/index.mjs
CHANGED
|
@@ -5393,6 +5393,92 @@ var _Code = class _Code {
|
|
|
5393
5393
|
constructor(session) {
|
|
5394
5394
|
this.session = session;
|
|
5395
5395
|
}
|
|
5396
|
+
/**
|
|
5397
|
+
* Parses the backend JSON response into a structured CodeExecutionResult
|
|
5398
|
+
* @param data Raw JSON string from backend
|
|
5399
|
+
*/
|
|
5400
|
+
parseBackendResponse(data) {
|
|
5401
|
+
let raw;
|
|
5402
|
+
try {
|
|
5403
|
+
raw = JSON.parse(data);
|
|
5404
|
+
if (typeof raw === "string") {
|
|
5405
|
+
try {
|
|
5406
|
+
raw = JSON.parse(raw);
|
|
5407
|
+
} catch (e) {
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5410
|
+
} catch (e) {
|
|
5411
|
+
return {
|
|
5412
|
+
requestId: "",
|
|
5413
|
+
// Will be filled later
|
|
5414
|
+
success: true,
|
|
5415
|
+
result: data,
|
|
5416
|
+
logs: { stdout: [data], stderr: [] },
|
|
5417
|
+
results: [{ text: data, isMainResult: true }]
|
|
5418
|
+
};
|
|
5419
|
+
}
|
|
5420
|
+
const logs = {
|
|
5421
|
+
stdout: raw.stdout || [],
|
|
5422
|
+
stderr: raw.stderr || []
|
|
5423
|
+
};
|
|
5424
|
+
const results = [];
|
|
5425
|
+
if (Array.isArray(raw.result)) {
|
|
5426
|
+
for (const itemStr of raw.result) {
|
|
5427
|
+
try {
|
|
5428
|
+
const itemMap = typeof itemStr === "string" ? JSON.parse(itemStr) : itemStr;
|
|
5429
|
+
const item = {};
|
|
5430
|
+
if (itemMap.isMainResult) item.isMainResult = true;
|
|
5431
|
+
if (itemMap.is_main_result) item.isMainResult = true;
|
|
5432
|
+
if (itemMap["text/plain"]) item.text = itemMap["text/plain"];
|
|
5433
|
+
if (itemMap["text/html"]) item.html = itemMap["text/html"];
|
|
5434
|
+
if (itemMap["text/markdown"]) item.markdown = itemMap["text/markdown"];
|
|
5435
|
+
if (itemMap["image/png"]) item.png = itemMap["image/png"];
|
|
5436
|
+
if (itemMap["image/jpeg"]) item.jpeg = itemMap["image/jpeg"];
|
|
5437
|
+
if (itemMap["image/svg+xml"]) item.svg = itemMap["image/svg+xml"];
|
|
5438
|
+
if (itemMap["text/latex"]) item.latex = itemMap["text/latex"];
|
|
5439
|
+
if (itemMap["application/json"]) item.json = itemMap["application/json"];
|
|
5440
|
+
if (itemMap["application/vnd.vegalite.v4+json"]) {
|
|
5441
|
+
item.chart = itemMap["application/vnd.vegalite.v4+json"];
|
|
5442
|
+
} else if (itemMap["application/vnd.vegalite.v5+json"]) {
|
|
5443
|
+
item.chart = itemMap["application/vnd.vegalite.v5+json"];
|
|
5444
|
+
} else if (itemMap["application/vnd.vega.v5+json"]) {
|
|
5445
|
+
item.chart = itemMap["application/vnd.vega.v5+json"];
|
|
5446
|
+
}
|
|
5447
|
+
results.push(item);
|
|
5448
|
+
} catch (e) {
|
|
5449
|
+
}
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
let error;
|
|
5453
|
+
if (raw.executionError) {
|
|
5454
|
+
error = {
|
|
5455
|
+
name: "ExecutionError",
|
|
5456
|
+
value: raw.executionError,
|
|
5457
|
+
traceback: ""
|
|
5458
|
+
};
|
|
5459
|
+
}
|
|
5460
|
+
let resultText = "";
|
|
5461
|
+
const mainRes = results.find((r) => r.isMainResult && r.text);
|
|
5462
|
+
if (mainRes && mainRes.text) {
|
|
5463
|
+
resultText = mainRes.text;
|
|
5464
|
+
} else if (results.length > 0 && results[0].text) {
|
|
5465
|
+
resultText = results[0].text;
|
|
5466
|
+
} else if (logs.stdout.length > 0) {
|
|
5467
|
+
resultText = logs.stdout.join("");
|
|
5468
|
+
}
|
|
5469
|
+
return {
|
|
5470
|
+
requestId: "",
|
|
5471
|
+
// Will be filled by caller
|
|
5472
|
+
success: !raw.executionError,
|
|
5473
|
+
result: resultText,
|
|
5474
|
+
errorMessage: raw.executionError,
|
|
5475
|
+
logs,
|
|
5476
|
+
results,
|
|
5477
|
+
error,
|
|
5478
|
+
executionTime: raw.executionTime || raw.execution_time,
|
|
5479
|
+
executionCount: raw.executionCount || raw.execution_count
|
|
5480
|
+
};
|
|
5481
|
+
}
|
|
5396
5482
|
/**
|
|
5397
5483
|
* Execute code in the specified language with a timeout.
|
|
5398
5484
|
* Corresponds to Python's run_code() method
|
|
@@ -5411,6 +5497,9 @@ var _Code = class _Code {
|
|
|
5411
5497
|
* if (result.success) {
|
|
5412
5498
|
* const codeResult = await result.session.code.runCode('print("Hello")', "python");
|
|
5413
5499
|
* console.log(codeResult.result);
|
|
5500
|
+
* if (codeResult.results) {
|
|
5501
|
+
* // Access rich output like images or charts
|
|
5502
|
+
* }
|
|
5414
5503
|
* await result.session.delete();
|
|
5415
5504
|
* }
|
|
5416
5505
|
* ```
|
|
@@ -5430,23 +5519,34 @@ var _Code = class _Code {
|
|
|
5430
5519
|
language,
|
|
5431
5520
|
timeout_s: timeoutS
|
|
5432
5521
|
};
|
|
5433
|
-
const response = await this.session.callMcpTool(
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5522
|
+
const response = await this.session.callMcpTool("run_code", args);
|
|
5523
|
+
let codeResult;
|
|
5524
|
+
if (response.success) {
|
|
5525
|
+
codeResult = this.parseBackendResponse(response.data);
|
|
5526
|
+
} else {
|
|
5527
|
+
try {
|
|
5528
|
+
if (response.errorMessage && response.errorMessage.trim().startsWith("{")) {
|
|
5529
|
+
codeResult = this.parseBackendResponse(response.errorMessage);
|
|
5530
|
+
codeResult.success = false;
|
|
5531
|
+
} else {
|
|
5532
|
+
return {
|
|
5533
|
+
requestId: response.requestId,
|
|
5534
|
+
success: false,
|
|
5535
|
+
result: "",
|
|
5536
|
+
errorMessage: response.errorMessage
|
|
5537
|
+
};
|
|
5538
|
+
}
|
|
5539
|
+
} catch {
|
|
5540
|
+
return {
|
|
5541
|
+
requestId: response.requestId,
|
|
5542
|
+
success: false,
|
|
5543
|
+
result: "",
|
|
5544
|
+
errorMessage: response.errorMessage
|
|
5545
|
+
};
|
|
5546
|
+
}
|
|
5444
5547
|
}
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
success: true,
|
|
5448
|
-
result: response.data || ""
|
|
5449
|
-
};
|
|
5548
|
+
codeResult.requestId = response.requestId;
|
|
5549
|
+
return codeResult;
|
|
5450
5550
|
} catch (error) {
|
|
5451
5551
|
return {
|
|
5452
5552
|
requestId: "",
|
|
@@ -10679,6 +10779,12 @@ var _Session = class _Session {
|
|
|
10679
10779
|
if (toolName === "run_code" && actualResult) {
|
|
10680
10780
|
const dataStr = typeof actualResult === "string" ? actualResult : JSON.stringify(actualResult);
|
|
10681
10781
|
logCodeExecutionOutput(requestId, dataStr);
|
|
10782
|
+
return {
|
|
10783
|
+
success: true,
|
|
10784
|
+
data: dataStr,
|
|
10785
|
+
errorMessage: "",
|
|
10786
|
+
requestId: ""
|
|
10787
|
+
};
|
|
10682
10788
|
}
|
|
10683
10789
|
return {
|
|
10684
10790
|
success: true,
|
|
@@ -10713,6 +10819,23 @@ var _Session = class _Session {
|
|
|
10713
10819
|
};
|
|
10714
10820
|
}
|
|
10715
10821
|
const data = response.body.data;
|
|
10822
|
+
const reqId = extractRequestId(response) || "";
|
|
10823
|
+
if (toolName === "run_code") {
|
|
10824
|
+
let dataStr = "";
|
|
10825
|
+
if (data && Array.isArray(data.content) && data.content.length > 0 && data.content[0].text) {
|
|
10826
|
+
dataStr = data.content[0].text;
|
|
10827
|
+
} else {
|
|
10828
|
+
dataStr = typeof response.body.data === "string" ? response.body.data : JSON.stringify(response.body.data);
|
|
10829
|
+
}
|
|
10830
|
+
logCodeExecutionOutput(reqId, dataStr);
|
|
10831
|
+
const isError = data.isError === true;
|
|
10832
|
+
return {
|
|
10833
|
+
success: !isError,
|
|
10834
|
+
data: dataStr,
|
|
10835
|
+
errorMessage: isError ? dataStr : "",
|
|
10836
|
+
requestId: reqId
|
|
10837
|
+
};
|
|
10838
|
+
}
|
|
10716
10839
|
if (data.isError) {
|
|
10717
10840
|
const errorContent = data.content || [];
|
|
10718
10841
|
const errorMessage = errorContent.map((item) => item.text || "Unknown error").join("; ");
|
|
@@ -10720,7 +10843,7 @@ var _Session = class _Session {
|
|
|
10720
10843
|
success: false,
|
|
10721
10844
|
data: "",
|
|
10722
10845
|
errorMessage,
|
|
10723
|
-
requestId:
|
|
10846
|
+
requestId: reqId
|
|
10724
10847
|
};
|
|
10725
10848
|
}
|
|
10726
10849
|
const content = data.content || [];
|
|
@@ -10728,11 +10851,6 @@ var _Session = class _Session {
|
|
|
10728
10851
|
if (content.length > 0 && content[0].text !== void 0) {
|
|
10729
10852
|
textContent = content[0].text;
|
|
10730
10853
|
}
|
|
10731
|
-
const reqId = extractRequestId(response) || "";
|
|
10732
|
-
if (toolName === "run_code" && data) {
|
|
10733
|
-
const dataStr = typeof response.body.data === "string" ? response.body.data : JSON.stringify(response.body.data);
|
|
10734
|
-
logCodeExecutionOutput(reqId, dataStr);
|
|
10735
|
-
}
|
|
10736
10854
|
return {
|
|
10737
10855
|
success: true,
|
|
10738
10856
|
data: textContent,
|