wuying-agentbay-sdk 0.4.0 → 0.4.2
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 +274 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +110 -5
- package/dist/index.d.ts +110 -5
- package/dist/index.mjs +274 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -6026,10 +6026,62 @@ var _Session = class _Session {
|
|
|
6026
6026
|
/**
|
|
6027
6027
|
* Delete this session.
|
|
6028
6028
|
*
|
|
6029
|
+
* @param syncContext - Whether to sync context data (trigger file uploads) before deleting the session. Defaults to false.
|
|
6029
6030
|
* @returns DeleteResult indicating success or failure and request ID
|
|
6030
6031
|
*/
|
|
6031
|
-
async delete() {
|
|
6032
|
+
async delete(syncContext = false) {
|
|
6032
6033
|
try {
|
|
6034
|
+
if (syncContext) {
|
|
6035
|
+
log("Triggering context synchronization before session deletion...");
|
|
6036
|
+
try {
|
|
6037
|
+
const syncResult = await this.context.sync();
|
|
6038
|
+
if (!syncResult.success) {
|
|
6039
|
+
log("Warning: Context sync operation returned failure status");
|
|
6040
|
+
}
|
|
6041
|
+
} catch (error) {
|
|
6042
|
+
logError("Warning: Failed to trigger context sync:", error);
|
|
6043
|
+
}
|
|
6044
|
+
const maxRetries = 150;
|
|
6045
|
+
const retryInterval = 2e3;
|
|
6046
|
+
for (let retry = 0; retry < maxRetries; retry++) {
|
|
6047
|
+
try {
|
|
6048
|
+
const infoResult = await this.context.info();
|
|
6049
|
+
let allCompleted = true;
|
|
6050
|
+
let hasFailure = false;
|
|
6051
|
+
let hasUploads = false;
|
|
6052
|
+
for (const item of infoResult.contextStatusData) {
|
|
6053
|
+
if (item.taskType !== "upload") {
|
|
6054
|
+
continue;
|
|
6055
|
+
}
|
|
6056
|
+
hasUploads = true;
|
|
6057
|
+
log(`Upload context ${item.contextId} status: ${item.status}, path: ${item.path}`);
|
|
6058
|
+
if (item.status !== "Success" && item.status !== "Failed") {
|
|
6059
|
+
allCompleted = false;
|
|
6060
|
+
break;
|
|
6061
|
+
}
|
|
6062
|
+
if (item.status === "Failed") {
|
|
6063
|
+
hasFailure = true;
|
|
6064
|
+
logError(`Upload failed for context ${item.contextId}: ${item.errorMessage}`);
|
|
6065
|
+
}
|
|
6066
|
+
}
|
|
6067
|
+
if (allCompleted || !hasUploads) {
|
|
6068
|
+
if (hasFailure) {
|
|
6069
|
+
log("Context upload completed with failures");
|
|
6070
|
+
} else if (hasUploads) {
|
|
6071
|
+
log("Context upload completed successfully");
|
|
6072
|
+
} else {
|
|
6073
|
+
log("No upload tasks found");
|
|
6074
|
+
}
|
|
6075
|
+
break;
|
|
6076
|
+
}
|
|
6077
|
+
log(`Waiting for context upload to complete, attempt ${retry + 1}/${maxRetries}`);
|
|
6078
|
+
await new Promise((resolve2) => setTimeout(resolve2, retryInterval));
|
|
6079
|
+
} catch (error) {
|
|
6080
|
+
logError(`Error checking context status on attempt ${retry + 1}:`, error);
|
|
6081
|
+
await new Promise((resolve2) => setTimeout(resolve2, retryInterval));
|
|
6082
|
+
}
|
|
6083
|
+
}
|
|
6084
|
+
}
|
|
6033
6085
|
const request = new ReleaseMcpSessionRequest({
|
|
6034
6086
|
authorization: `Bearer ${this.getAPIKey()}`,
|
|
6035
6087
|
sessionId: this.sessionId
|
|
@@ -6333,19 +6385,21 @@ var _AgentBay = class _AgentBay {
|
|
|
6333
6385
|
if (params.imageId) {
|
|
6334
6386
|
request.imageId = params.imageId;
|
|
6335
6387
|
}
|
|
6388
|
+
let hasPersistenceData = false;
|
|
6336
6389
|
if (params.contextSync && params.contextSync.length > 0) {
|
|
6337
6390
|
const persistenceDataList = [];
|
|
6338
6391
|
for (const contextSync of params.contextSync) {
|
|
6339
|
-
const persistenceItem = {
|
|
6392
|
+
const persistenceItem = new CreateMcpSessionRequestPersistenceDataList({
|
|
6340
6393
|
contextId: contextSync.contextId,
|
|
6341
6394
|
path: contextSync.path
|
|
6342
|
-
};
|
|
6395
|
+
});
|
|
6343
6396
|
if (contextSync.policy) {
|
|
6344
6397
|
persistenceItem.policy = JSON.stringify(contextSync.policy);
|
|
6345
6398
|
}
|
|
6346
6399
|
persistenceDataList.push(persistenceItem);
|
|
6347
6400
|
}
|
|
6348
6401
|
request.persistenceDataList = persistenceDataList;
|
|
6402
|
+
hasPersistenceData = persistenceDataList.length > 0;
|
|
6349
6403
|
}
|
|
6350
6404
|
log("API Call: CreateMcpSession");
|
|
6351
6405
|
let requestLog = "Request: ";
|
|
@@ -6404,6 +6458,42 @@ var _AgentBay = class _AgentBay {
|
|
|
6404
6458
|
session.resourceUrl = resourceUrl;
|
|
6405
6459
|
}
|
|
6406
6460
|
this.sessions.set(session.sessionId, session);
|
|
6461
|
+
if (hasPersistenceData) {
|
|
6462
|
+
log("Waiting for context synchronization to complete...");
|
|
6463
|
+
const maxRetries = 150;
|
|
6464
|
+
const retryInterval = 2e3;
|
|
6465
|
+
for (let retry = 0; retry < maxRetries; retry++) {
|
|
6466
|
+
try {
|
|
6467
|
+
const infoResult = await session.context.info();
|
|
6468
|
+
let allCompleted = true;
|
|
6469
|
+
let hasFailure = false;
|
|
6470
|
+
for (const item of infoResult.contextStatusData) {
|
|
6471
|
+
log(`Context ${item.contextId} status: ${item.status}, path: ${item.path}`);
|
|
6472
|
+
if (item.status !== "Success" && item.status !== "Failed") {
|
|
6473
|
+
allCompleted = false;
|
|
6474
|
+
break;
|
|
6475
|
+
}
|
|
6476
|
+
if (item.status === "Failed") {
|
|
6477
|
+
hasFailure = true;
|
|
6478
|
+
logError(`Context synchronization failed for ${item.contextId}: ${item.errorMessage}`);
|
|
6479
|
+
}
|
|
6480
|
+
}
|
|
6481
|
+
if (allCompleted || infoResult.contextStatusData.length === 0) {
|
|
6482
|
+
if (hasFailure) {
|
|
6483
|
+
log("Context synchronization completed with failures");
|
|
6484
|
+
} else {
|
|
6485
|
+
log("Context synchronization completed successfully");
|
|
6486
|
+
}
|
|
6487
|
+
break;
|
|
6488
|
+
}
|
|
6489
|
+
log(`Waiting for context synchronization, attempt ${retry + 1}/${maxRetries}`);
|
|
6490
|
+
await new Promise((resolve2) => setTimeout(resolve2, retryInterval));
|
|
6491
|
+
} catch (error) {
|
|
6492
|
+
logError(`Error checking context status on attempt ${retry + 1}: ${error}`);
|
|
6493
|
+
await new Promise((resolve2) => setTimeout(resolve2, retryInterval));
|
|
6494
|
+
}
|
|
6495
|
+
}
|
|
6496
|
+
}
|
|
6407
6497
|
return {
|
|
6408
6498
|
requestId,
|
|
6409
6499
|
success: true,
|
|
@@ -6516,11 +6606,12 @@ var _AgentBay = class _AgentBay {
|
|
|
6516
6606
|
* Delete a session by session object.
|
|
6517
6607
|
*
|
|
6518
6608
|
* @param session - The session to delete.
|
|
6609
|
+
* @param syncContext - Whether to sync context data (trigger file uploads) before deleting the session. Defaults to false.
|
|
6519
6610
|
* @returns DeleteResult indicating success or failure and request ID
|
|
6520
6611
|
*/
|
|
6521
|
-
async delete(session) {
|
|
6612
|
+
async delete(session, syncContext = false) {
|
|
6522
6613
|
try {
|
|
6523
|
-
const deleteResult = await session.delete();
|
|
6614
|
+
const deleteResult = await session.delete(syncContext);
|
|
6524
6615
|
this.sessions.delete(session.sessionId);
|
|
6525
6616
|
return deleteResult;
|
|
6526
6617
|
} catch (error) {
|
|
@@ -6549,6 +6640,171 @@ var _AgentBay = class _AgentBay {
|
|
|
6549
6640
|
};
|
|
6550
6641
|
__name(_AgentBay, "AgentBay");
|
|
6551
6642
|
var AgentBay = _AgentBay;
|
|
6643
|
+
|
|
6644
|
+
// src/context-sync.ts
|
|
6645
|
+
init_esm_shims();
|
|
6646
|
+
var UploadStrategy = /* @__PURE__ */ ((UploadStrategy2) => {
|
|
6647
|
+
UploadStrategy2["UploadBeforeResourceRelease"] = "UploadBeforeResourceRelease";
|
|
6648
|
+
return UploadStrategy2;
|
|
6649
|
+
})(UploadStrategy || {});
|
|
6650
|
+
var DownloadStrategy = /* @__PURE__ */ ((DownloadStrategy2) => {
|
|
6651
|
+
DownloadStrategy2["DownloadAsync"] = "DownloadAsync";
|
|
6652
|
+
return DownloadStrategy2;
|
|
6653
|
+
})(DownloadStrategy || {});
|
|
6654
|
+
var _ContextSync = class _ContextSync {
|
|
6655
|
+
constructor(contextId, path3, policy) {
|
|
6656
|
+
this.contextId = contextId;
|
|
6657
|
+
this.path = path3;
|
|
6658
|
+
this.policy = policy;
|
|
6659
|
+
}
|
|
6660
|
+
// WithPolicy sets the policy and returns the context sync for chaining
|
|
6661
|
+
withPolicy(policy) {
|
|
6662
|
+
this.policy = policy;
|
|
6663
|
+
return this;
|
|
6664
|
+
}
|
|
6665
|
+
};
|
|
6666
|
+
__name(_ContextSync, "ContextSync");
|
|
6667
|
+
var ContextSync = _ContextSync;
|
|
6668
|
+
function newUploadPolicy() {
|
|
6669
|
+
return {
|
|
6670
|
+
autoUpload: true,
|
|
6671
|
+
uploadStrategy: "UploadBeforeResourceRelease" /* UploadBeforeResourceRelease */,
|
|
6672
|
+
period: 30
|
|
6673
|
+
// Default to 30 minutes
|
|
6674
|
+
};
|
|
6675
|
+
}
|
|
6676
|
+
__name(newUploadPolicy, "newUploadPolicy");
|
|
6677
|
+
function newDownloadPolicy() {
|
|
6678
|
+
return {
|
|
6679
|
+
autoDownload: true,
|
|
6680
|
+
downloadStrategy: "DownloadAsync" /* DownloadAsync */
|
|
6681
|
+
};
|
|
6682
|
+
}
|
|
6683
|
+
__name(newDownloadPolicy, "newDownloadPolicy");
|
|
6684
|
+
function newDeletePolicy() {
|
|
6685
|
+
return {
|
|
6686
|
+
syncLocalFile: true
|
|
6687
|
+
};
|
|
6688
|
+
}
|
|
6689
|
+
__name(newDeletePolicy, "newDeletePolicy");
|
|
6690
|
+
function newSyncPolicy() {
|
|
6691
|
+
return {
|
|
6692
|
+
uploadPolicy: newUploadPolicy(),
|
|
6693
|
+
downloadPolicy: newDownloadPolicy(),
|
|
6694
|
+
deletePolicy: newDeletePolicy(),
|
|
6695
|
+
bwList: {
|
|
6696
|
+
whiteLists: [
|
|
6697
|
+
{
|
|
6698
|
+
path: "",
|
|
6699
|
+
excludePaths: []
|
|
6700
|
+
}
|
|
6701
|
+
]
|
|
6702
|
+
}
|
|
6703
|
+
};
|
|
6704
|
+
}
|
|
6705
|
+
__name(newSyncPolicy, "newSyncPolicy");
|
|
6706
|
+
function newContextSync(contextId, path3, policy) {
|
|
6707
|
+
return new ContextSync(contextId, path3, policy);
|
|
6708
|
+
}
|
|
6709
|
+
__name(newContextSync, "newContextSync");
|
|
6710
|
+
|
|
6711
|
+
// src/session-params.ts
|
|
6712
|
+
init_esm_shims();
|
|
6713
|
+
var _CreateSessionParams = class _CreateSessionParams {
|
|
6714
|
+
constructor() {
|
|
6715
|
+
this.labels = {};
|
|
6716
|
+
this.contextSync = [];
|
|
6717
|
+
}
|
|
6718
|
+
/**
|
|
6719
|
+
* WithLabels sets the labels for the session parameters and returns the updated parameters.
|
|
6720
|
+
*/
|
|
6721
|
+
withLabels(labels) {
|
|
6722
|
+
this.labels = labels;
|
|
6723
|
+
return this;
|
|
6724
|
+
}
|
|
6725
|
+
/**
|
|
6726
|
+
* WithContextID sets the context ID for the session parameters and returns the updated parameters.
|
|
6727
|
+
*/
|
|
6728
|
+
withContextID(contextId) {
|
|
6729
|
+
this.contextId = contextId;
|
|
6730
|
+
return this;
|
|
6731
|
+
}
|
|
6732
|
+
/**
|
|
6733
|
+
* WithImageId sets the image ID for the session parameters and returns the updated parameters.
|
|
6734
|
+
*/
|
|
6735
|
+
withImageId(imageId) {
|
|
6736
|
+
this.imageId = imageId;
|
|
6737
|
+
return this;
|
|
6738
|
+
}
|
|
6739
|
+
/**
|
|
6740
|
+
* GetLabelsJSON returns the labels as a JSON string.
|
|
6741
|
+
* Returns an object with success status and result/error message to match Go version behavior.
|
|
6742
|
+
*/
|
|
6743
|
+
getLabelsJSON() {
|
|
6744
|
+
if (Object.keys(this.labels).length === 0) {
|
|
6745
|
+
return { result: "" };
|
|
6746
|
+
}
|
|
6747
|
+
try {
|
|
6748
|
+
const labelsJSON = JSON.stringify(this.labels);
|
|
6749
|
+
return { result: labelsJSON };
|
|
6750
|
+
} catch (error) {
|
|
6751
|
+
return {
|
|
6752
|
+
result: "",
|
|
6753
|
+
error: `Failed to marshal labels to JSON: ${error}`
|
|
6754
|
+
};
|
|
6755
|
+
}
|
|
6756
|
+
}
|
|
6757
|
+
/**
|
|
6758
|
+
* AddContextSync adds a context sync configuration to the session parameters.
|
|
6759
|
+
*/
|
|
6760
|
+
addContextSync(contextId, path3, policy) {
|
|
6761
|
+
const contextSync = new ContextSync(contextId, path3, policy);
|
|
6762
|
+
this.contextSync.push(contextSync);
|
|
6763
|
+
return this;
|
|
6764
|
+
}
|
|
6765
|
+
/**
|
|
6766
|
+
* AddContextSyncConfig adds a pre-configured context sync to the session parameters.
|
|
6767
|
+
*/
|
|
6768
|
+
addContextSyncConfig(contextSync) {
|
|
6769
|
+
this.contextSync.push(contextSync);
|
|
6770
|
+
return this;
|
|
6771
|
+
}
|
|
6772
|
+
/**
|
|
6773
|
+
* WithContextSync sets the context sync configurations for the session parameters.
|
|
6774
|
+
*/
|
|
6775
|
+
withContextSync(contextSyncs) {
|
|
6776
|
+
this.contextSync = contextSyncs;
|
|
6777
|
+
return this;
|
|
6778
|
+
}
|
|
6779
|
+
/**
|
|
6780
|
+
* Convert to plain object for JSON serialization
|
|
6781
|
+
*/
|
|
6782
|
+
toJSON() {
|
|
6783
|
+
return {
|
|
6784
|
+
labels: this.labels,
|
|
6785
|
+
contextId: this.contextId,
|
|
6786
|
+
imageId: this.imageId,
|
|
6787
|
+
contextSync: this.contextSync
|
|
6788
|
+
};
|
|
6789
|
+
}
|
|
6790
|
+
/**
|
|
6791
|
+
* Create from plain object
|
|
6792
|
+
*/
|
|
6793
|
+
static fromJSON(config) {
|
|
6794
|
+
const params = new _CreateSessionParams();
|
|
6795
|
+
params.labels = config.labels || {};
|
|
6796
|
+
params.contextId = config.contextId;
|
|
6797
|
+
params.imageId = config.imageId;
|
|
6798
|
+
params.contextSync = config.contextSync || [];
|
|
6799
|
+
return params;
|
|
6800
|
+
}
|
|
6801
|
+
};
|
|
6802
|
+
__name(_CreateSessionParams, "CreateSessionParams");
|
|
6803
|
+
var CreateSessionParams = _CreateSessionParams;
|
|
6804
|
+
function newCreateSessionParams() {
|
|
6805
|
+
return new CreateSessionParams();
|
|
6806
|
+
}
|
|
6807
|
+
__name(newCreateSessionParams, "newCreateSessionParams");
|
|
6552
6808
|
export {
|
|
6553
6809
|
APIError,
|
|
6554
6810
|
AgentBay,
|
|
@@ -6567,16 +6823,20 @@ export {
|
|
|
6567
6823
|
Command,
|
|
6568
6824
|
CommandError,
|
|
6569
6825
|
Context,
|
|
6826
|
+
ContextManager,
|
|
6570
6827
|
ContextService,
|
|
6828
|
+
ContextSync,
|
|
6571
6829
|
CreateMcpSessionRequest,
|
|
6572
6830
|
CreateMcpSessionRequestPersistenceDataList,
|
|
6573
6831
|
CreateMcpSessionResponse,
|
|
6574
6832
|
CreateMcpSessionResponseBody,
|
|
6575
6833
|
CreateMcpSessionResponseBodyData,
|
|
6576
6834
|
CreateMcpSessionShrinkRequest,
|
|
6835
|
+
CreateSessionParams,
|
|
6577
6836
|
DeleteContextRequest,
|
|
6578
6837
|
DeleteContextResponse,
|
|
6579
6838
|
DeleteContextResponseBody,
|
|
6839
|
+
DownloadStrategy,
|
|
6580
6840
|
FileError,
|
|
6581
6841
|
FileSystem,
|
|
6582
6842
|
GetContextInfoRequest,
|
|
@@ -6630,8 +6890,16 @@ export {
|
|
|
6630
6890
|
SyncContextResponseBody,
|
|
6631
6891
|
UI,
|
|
6632
6892
|
UIError,
|
|
6893
|
+
UploadStrategy,
|
|
6633
6894
|
log,
|
|
6634
|
-
logError
|
|
6895
|
+
logError,
|
|
6896
|
+
newContextManager,
|
|
6897
|
+
newContextSync,
|
|
6898
|
+
newCreateSessionParams,
|
|
6899
|
+
newDeletePolicy,
|
|
6900
|
+
newDownloadPolicy,
|
|
6901
|
+
newSyncPolicy,
|
|
6902
|
+
newUploadPolicy
|
|
6635
6903
|
};
|
|
6636
6904
|
//# sourceMappingURL=index.mjs.map
|
|
6637
6905
|
|