wuying-agentbay-sdk 0.1.0 → 0.4.0
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/README.md +124 -61
- package/dist/index.cjs +6621 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +2633 -0
- package/dist/index.d.ts +2633 -0
- package/dist/index.mjs +6637 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +84 -48
- package/dist/src/adb/adb.d.ts +0 -20
- package/dist/src/adb/adb.js +0 -57
- package/dist/src/adb/index.d.ts +0 -1
- package/dist/src/adb/index.js +0 -17
- package/dist/src/agent-bay.d.ts +0 -68
- package/dist/src/agent-bay.js +0 -213
- package/dist/src/api/client.d.ts +0 -191
- package/dist/src/api/client.js +0 -629
- package/dist/src/api/index.d.ts +0 -4
- package/dist/src/api/index.js +0 -26
- package/dist/src/api/models/CallMcpToolRequest.d.ts +0 -21
- package/dist/src/api/models/CallMcpToolRequest.js +0 -71
- package/dist/src/api/models/CallMcpToolResponse.d.ts +0 -19
- package/dist/src/api/models/CallMcpToolResponse.js +0 -68
- package/dist/src/api/models/CallMcpToolResponseBody.d.ts +0 -19
- package/dist/src/api/models/CallMcpToolResponseBody.js +0 -67
- package/dist/src/api/models/CreateMcpSessionRequest.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionRequest.js +0 -67
- package/dist/src/api/models/CreateMcpSessionResponse.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionResponse.js +0 -68
- package/dist/src/api/models/CreateMcpSessionResponseBody.d.ts +0 -20
- package/dist/src/api/models/CreateMcpSessionResponseBody.js +0 -71
- package/dist/src/api/models/CreateMcpSessionResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionResponseBodyData.js +0 -67
- package/dist/src/api/models/DeleteContextRequest.d.ts +0 -15
- package/dist/src/api/models/DeleteContextRequest.js +0 -59
- package/dist/src/api/models/DeleteContextResponse.d.ts +0 -19
- package/dist/src/api/models/DeleteContextResponse.js +0 -68
- package/dist/src/api/models/DeleteContextResponseBody.d.ts +0 -18
- package/dist/src/api/models/DeleteContextResponseBody.js +0 -65
- package/dist/src/api/models/GetContextRequest.d.ts +0 -16
- package/dist/src/api/models/GetContextRequest.js +0 -61
- package/dist/src/api/models/GetContextResponse.d.ts +0 -19
- package/dist/src/api/models/GetContextResponse.js +0 -68
- package/dist/src/api/models/GetContextResponseBody.d.ts +0 -20
- package/dist/src/api/models/GetContextResponseBody.js +0 -71
- package/dist/src/api/models/GetContextResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/GetContextResponseBodyData.js +0 -67
- package/dist/src/api/models/GetLabelRequest.d.ts +0 -17
- package/dist/src/api/models/GetLabelRequest.js +0 -63
- package/dist/src/api/models/GetLabelResponse.d.ts +0 -19
- package/dist/src/api/models/GetLabelResponse.js +0 -68
- package/dist/src/api/models/GetLabelResponseBody.d.ts +0 -23
- package/dist/src/api/models/GetLabelResponseBody.js +0 -77
- package/dist/src/api/models/GetLabelResponseBodyData.d.ts +0 -14
- package/dist/src/api/models/GetLabelResponseBodyData.js +0 -57
- package/dist/src/api/models/GetLinkRequest.d.ts +0 -15
- package/dist/src/api/models/GetLinkRequest.js +0 -59
- package/dist/src/api/models/GetLinkResponse.d.ts +0 -19
- package/dist/src/api/models/GetLinkResponse.js +0 -68
- package/dist/src/api/models/GetLinkResponseBody.d.ts +0 -19
- package/dist/src/api/models/GetLinkResponseBody.js +0 -67
- package/dist/src/api/models/GetMcpResourceRequest.d.ts +0 -15
- package/dist/src/api/models/GetMcpResourceRequest.js +0 -59
- package/dist/src/api/models/GetMcpResourceResponse.d.ts +0 -19
- package/dist/src/api/models/GetMcpResourceResponse.js +0 -68
- package/dist/src/api/models/GetMcpResourceResponseBody.d.ts +0 -20
- package/dist/src/api/models/GetMcpResourceResponseBody.js +0 -71
- package/dist/src/api/models/GetMcpResourceResponseBodyData.d.ts +0 -17
- package/dist/src/api/models/GetMcpResourceResponseBodyData.js +0 -65
- package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.d.ts +0 -18
- package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.js +0 -65
- package/dist/src/api/models/ListContextsRequest.d.ts +0 -16
- package/dist/src/api/models/ListContextsRequest.js +0 -61
- package/dist/src/api/models/ListContextsResponse.d.ts +0 -19
- package/dist/src/api/models/ListContextsResponse.js +0 -68
- package/dist/src/api/models/ListContextsResponseBody.d.ts +0 -23
- package/dist/src/api/models/ListContextsResponseBody.js +0 -77
- package/dist/src/api/models/ListContextsResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/ListContextsResponseBodyData.js +0 -67
- package/dist/src/api/models/ListSessionRequest.d.ts +0 -17
- package/dist/src/api/models/ListSessionRequest.js +0 -63
- package/dist/src/api/models/ListSessionResponse.d.ts +0 -19
- package/dist/src/api/models/ListSessionResponse.js +0 -68
- package/dist/src/api/models/ListSessionResponseBody.d.ts +0 -23
- package/dist/src/api/models/ListSessionResponseBody.js +0 -77
- package/dist/src/api/models/ListSessionResponseBodyData.d.ts +0 -14
- package/dist/src/api/models/ListSessionResponseBodyData.js +0 -57
- package/dist/src/api/models/ModifyContextRequest.d.ts +0 -16
- package/dist/src/api/models/ModifyContextRequest.js +0 -61
- package/dist/src/api/models/ModifyContextResponse.d.ts +0 -19
- package/dist/src/api/models/ModifyContextResponse.js +0 -68
- package/dist/src/api/models/ModifyContextResponseBody.d.ts +0 -18
- package/dist/src/api/models/ModifyContextResponseBody.js +0 -65
- package/dist/src/api/models/ReleaseMcpSessionRequest.d.ts +0 -15
- package/dist/src/api/models/ReleaseMcpSessionRequest.js +0 -59
- package/dist/src/api/models/ReleaseMcpSessionResponse.d.ts +0 -19
- package/dist/src/api/models/ReleaseMcpSessionResponse.js +0 -68
- package/dist/src/api/models/ReleaseMcpSessionResponseBody.d.ts +0 -18
- package/dist/src/api/models/ReleaseMcpSessionResponseBody.js +0 -65
- package/dist/src/api/models/SetLabelRequest.d.ts +0 -16
- package/dist/src/api/models/SetLabelRequest.js +0 -61
- package/dist/src/api/models/SetLabelResponse.d.ts +0 -19
- package/dist/src/api/models/SetLabelResponse.js +0 -68
- package/dist/src/api/models/SetLabelResponseBody.d.ts +0 -18
- package/dist/src/api/models/SetLabelResponseBody.js +0 -65
- package/dist/src/api/models/model.d.ts +0 -43
- package/dist/src/api/models/model.js +0 -89
- package/dist/src/application/application.d.ts +0 -88
- package/dist/src/application/application.js +0 -172
- package/dist/src/application/index.d.ts +0 -1
- package/dist/src/application/index.js +0 -17
- package/dist/src/command/command.d.ts +0 -43
- package/dist/src/command/command.js +0 -120
- package/dist/src/command/index.d.ts +0 -1
- package/dist/src/command/index.js +0 -17
- package/dist/src/config.d.ts +0 -15
- package/dist/src/config.js +0 -114
- package/dist/src/context.d.ts +0 -87
- package/dist/src/context.js +0 -208
- package/dist/src/exceptions.d.ts +0 -30
- package/dist/src/exceptions.js +0 -58
- package/dist/src/filesystem/filesystem.d.ts +0 -109
- package/dist/src/filesystem/filesystem.js +0 -245
- package/dist/src/filesystem/index.d.ts +0 -1
- package/dist/src/filesystem/index.js +0 -17
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.js +0 -32
- package/dist/src/oss/index.d.ts +0 -1
- package/dist/src/oss/index.js +0 -5
- package/dist/src/oss/oss.d.ts +0 -80
- package/dist/src/oss/oss.js +0 -233
- package/dist/src/session.d.ts +0 -99
- package/dist/src/session.js +0 -226
- package/dist/src/ui/index.d.ts +0 -1
- package/dist/src/ui/index.js +0 -17
- package/dist/src/ui/ui.d.ts +0 -95
- package/dist/src/ui/ui.js +0 -206
- package/dist/src/utils/logger.d.ts +0 -15
- package/dist/src/utils/logger.js +0 -48
- package/dist/src/window/index.d.ts +0 -1
- package/dist/src/window/index.js +0 -17
- package/dist/src/window/window.d.ts +0 -109
- package/dist/src/window/window.js +0 -220
- package/dist/tests/agent-bay.test.d.ts +0 -1
- package/dist/tests/agent-bay.test.js +0 -366
- package/dist/tests/integration/context-persistence.test.d.ts +0 -1
- package/dist/tests/integration/context-persistence.test.js +0 -226
- package/dist/tests/integration/context-session.test.d.ts +0 -1
- package/dist/tests/integration/context-session.test.js +0 -223
- package/dist/tests/integration/window-operations.test.d.ts +0 -1
- package/dist/tests/integration/window-operations.test.js +0 -228
- package/dist/tests/unit/adb.test.d.ts +0 -1
- package/dist/tests/unit/adb.test.js +0 -60
- package/dist/tests/unit/agent-bay.test.d.ts +0 -1
- package/dist/tests/unit/agent-bay.test.js +0 -182
- package/dist/tests/unit/application.test.d.ts +0 -1
- package/dist/tests/unit/application.test.js +0 -260
- package/dist/tests/unit/command.test.d.ts +0 -1
- package/dist/tests/unit/command.test.js +0 -252
- package/dist/tests/unit/context.test.d.ts +0 -1
- package/dist/tests/unit/context.test.js +0 -199
- package/dist/tests/unit/filesystem.test.d.ts +0 -1
- package/dist/tests/unit/filesystem.test.js +0 -493
- package/dist/tests/unit/oss.test.d.ts +0 -1
- package/dist/tests/unit/oss.test.js +0 -243
- package/dist/tests/unit/session-labels.test.d.ts +0 -1
- package/dist/tests/unit/session-labels.test.js +0 -138
- package/dist/tests/unit/session-params.test.d.ts +0 -1
- package/dist/tests/unit/session-params.test.js +0 -78
- package/dist/tests/unit/session.test.d.ts +0 -1
- package/dist/tests/unit/session.test.js +0 -204
- package/dist/tests/unit/ui.test.d.ts +0 -1
- package/dist/tests/unit/ui.test.js +0 -158
- package/dist/tests/unit/window.test.d.ts +0 -1
- package/dist/tests/unit/window.test.js +0 -331
- package/dist/tests/utils/test-helpers.d.ts +0 -35
- package/dist/tests/utils/test-helpers.js +0 -79
package/package.json
CHANGED
|
@@ -1,50 +1,86 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
2
|
+
"name": "wuying-agentbay-sdk",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "TypeScript SDK for interacting with the Wuying AgentBay cloud runtime environment",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup src/index.ts --dts --format cjs,esm",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"test:unit": "jest tests/unit",
|
|
20
|
+
"test:integration": "jest tests/integration",
|
|
21
|
+
"test:coverage": "jest --coverage",
|
|
22
|
+
"lint": "eslint src/**/*.ts",
|
|
23
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
24
|
+
"prepare": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Wuying AI Team",
|
|
28
|
+
"email": "wuying-ai-team@alibabacloud.com",
|
|
29
|
+
"url": "https://github.com/aliyun/wuying-agentbay-sdk"
|
|
30
|
+
},
|
|
31
|
+
"contributors": [
|
|
32
|
+
{
|
|
33
|
+
"name": "yuebing.yb",
|
|
34
|
+
"email": "yuebing.yb@alibaba-inc.com"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"homepage": "https://github.com/aliyun/wuying-agentbay-sdk",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/aliyun/wuying-agentbay-sdk/issues"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"wuying",
|
|
44
|
+
"agentbay",
|
|
45
|
+
"sdk",
|
|
46
|
+
"alibaba",
|
|
47
|
+
"cloud",
|
|
48
|
+
"runtime"
|
|
49
|
+
],
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/chai": "^5.2.2",
|
|
52
|
+
"@types/jest": "^29.5.0",
|
|
53
|
+
"@types/mocha": "^10.0.10",
|
|
54
|
+
"@types/node": "^18.15.0",
|
|
55
|
+
"@types/sinon": "^10.0.0",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.54.0",
|
|
58
|
+
"axios-mock-adapter": "^2.1.0",
|
|
59
|
+
"chai": "^4.3.7",
|
|
60
|
+
"dotenv": "^16.5.0",
|
|
61
|
+
"eslint": "^8.35.0",
|
|
62
|
+
"jest": "^29.5.0",
|
|
63
|
+
"prettier": "^2.8.4",
|
|
64
|
+
"sinon": "^15.2.0",
|
|
65
|
+
"ts-jest": "^29.1.0",
|
|
66
|
+
"ts-node": "^10.9.2",
|
|
67
|
+
"tsup": "^8.5.0",
|
|
68
|
+
"typescript": "^5.0.0"
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@alicloud/openapi-core": "^1.0.4",
|
|
72
|
+
"@darabonba/typescript": "^1.0.0",
|
|
73
|
+
"axios": "^1.3.4"
|
|
74
|
+
},
|
|
75
|
+
"sideEffects": false,
|
|
76
|
+
"files": [
|
|
77
|
+
"dist/**/*"
|
|
78
|
+
],
|
|
79
|
+
"repository": {
|
|
80
|
+
"type": "git",
|
|
81
|
+
"url": "https://github.com/aliyun/wuying-agentbay-sdk.git"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">=14.0.0"
|
|
85
|
+
}
|
|
50
86
|
}
|
package/dist/src/adb/adb.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Session } from '../session';
|
|
2
|
-
/**
|
|
3
|
-
* Adb handles ADB operations in the AgentBay cloud environment.
|
|
4
|
-
*/
|
|
5
|
-
export declare class Adb {
|
|
6
|
-
private session;
|
|
7
|
-
/**
|
|
8
|
-
* Create a new Adb instance.
|
|
9
|
-
*
|
|
10
|
-
* @param session - The session to use for ADB operations
|
|
11
|
-
*/
|
|
12
|
-
constructor(session: Session);
|
|
13
|
-
/**
|
|
14
|
-
* Execute an ADB shell command in the mobile environment.
|
|
15
|
-
*
|
|
16
|
-
* @param command - The ADB shell command to execute
|
|
17
|
-
* @returns The output of the ADB shell command
|
|
18
|
-
*/
|
|
19
|
-
shell(command: string): Promise<string>;
|
|
20
|
-
}
|
package/dist/src/adb/adb.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Adb = void 0;
|
|
4
|
-
const model_1 = require("../api/models/model");
|
|
5
|
-
/**
|
|
6
|
-
* Adb handles ADB operations in the AgentBay cloud environment.
|
|
7
|
-
*/
|
|
8
|
-
class Adb {
|
|
9
|
-
/**
|
|
10
|
-
* Create a new Adb instance.
|
|
11
|
-
*
|
|
12
|
-
* @param session - The session to use for ADB operations
|
|
13
|
-
*/
|
|
14
|
-
constructor(session) {
|
|
15
|
-
this.session = session;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Execute an ADB shell command in the mobile environment.
|
|
19
|
-
*
|
|
20
|
-
* @param command - The ADB shell command to execute
|
|
21
|
-
* @returns The output of the ADB shell command
|
|
22
|
-
*/
|
|
23
|
-
async shell(command) {
|
|
24
|
-
try {
|
|
25
|
-
const args = {
|
|
26
|
-
command
|
|
27
|
-
};
|
|
28
|
-
const callToolRequest = new model_1.CallMcpToolRequest({
|
|
29
|
-
authorization: `Bearer ${this.session.getAPIKey()}`,
|
|
30
|
-
sessionId: this.session.getSessionId(),
|
|
31
|
-
name: 'shell',
|
|
32
|
-
args: JSON.stringify(args)
|
|
33
|
-
});
|
|
34
|
-
const response = await this.session.getClient().callMcpTool(callToolRequest);
|
|
35
|
-
if (!response.body?.data) {
|
|
36
|
-
throw new Error('Invalid response data format');
|
|
37
|
-
}
|
|
38
|
-
// Extract content from response
|
|
39
|
-
const data = response.body.data;
|
|
40
|
-
if (!data.content || !Array.isArray(data.content)) {
|
|
41
|
-
throw new Error('Content field not found or not an array');
|
|
42
|
-
}
|
|
43
|
-
// Concatenate all text fields
|
|
44
|
-
let fullText = '';
|
|
45
|
-
for (const item of data.content) {
|
|
46
|
-
if (item && typeof item === 'object' && 'text' in item) {
|
|
47
|
-
fullText += item.text + '\n';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return fullText;
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
throw new Error(`Failed to execute ADB shell command: ${error}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.Adb = Adb;
|
package/dist/src/adb/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './adb';
|
package/dist/src/adb/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./adb"), exports);
|
package/dist/src/agent-bay.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Session } from './session';
|
|
2
|
-
import { ContextService } from './context';
|
|
3
|
-
import Client from './api/client';
|
|
4
|
-
import 'dotenv/config';
|
|
5
|
-
/**
|
|
6
|
-
* Main class for interacting with the AgentBay cloud runtime environment.
|
|
7
|
-
*/
|
|
8
|
-
export declare class AgentBay {
|
|
9
|
-
private apiKey;
|
|
10
|
-
private client;
|
|
11
|
-
private regionId;
|
|
12
|
-
private endpoint;
|
|
13
|
-
private sessions;
|
|
14
|
-
/**
|
|
15
|
-
* Context service for managing persistent contexts.
|
|
16
|
-
*/
|
|
17
|
-
context: ContextService;
|
|
18
|
-
/**
|
|
19
|
-
* Initialize the AgentBay client.
|
|
20
|
-
*
|
|
21
|
-
* @param options - Configuration options
|
|
22
|
-
* @param options.apiKey - API key for authentication. If not provided, will look for AGENTBAY_API_KEY environment variable.
|
|
23
|
-
*/
|
|
24
|
-
constructor(options?: {
|
|
25
|
-
apiKey?: string;
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Create a new session in the AgentBay cloud environment.
|
|
29
|
-
*
|
|
30
|
-
* @param options - Optional parameters for creating the session
|
|
31
|
-
* @param options.contextId - ID of the context to bind to the session
|
|
32
|
-
* @param options.labels - Custom labels for the session
|
|
33
|
-
* @returns A new Session object.
|
|
34
|
-
*/
|
|
35
|
-
create(options?: {
|
|
36
|
-
contextId?: string;
|
|
37
|
-
labels?: Record<string, string>;
|
|
38
|
-
imageId?: string;
|
|
39
|
-
}): Promise<Session>;
|
|
40
|
-
/**
|
|
41
|
-
* List all available sessions.
|
|
42
|
-
*
|
|
43
|
-
* @returns A list of session objects.
|
|
44
|
-
*/
|
|
45
|
-
list(): Session[];
|
|
46
|
-
/**
|
|
47
|
-
* List sessions filtered by the provided labels.
|
|
48
|
-
* It returns sessions that match all the specified labels.
|
|
49
|
-
*
|
|
50
|
-
* @param labels - The labels to filter by.
|
|
51
|
-
* @returns A list of session objects that match the labels.
|
|
52
|
-
*/
|
|
53
|
-
listByLabels(labels: Record<string, string>): Promise<Session[]>;
|
|
54
|
-
/**
|
|
55
|
-
* Delete a session by ID.
|
|
56
|
-
*
|
|
57
|
-
* @param sessionId - The ID of the session to delete.
|
|
58
|
-
* @returns True if the session was successfully deleted.
|
|
59
|
-
*/
|
|
60
|
-
delete(session: Session): Promise<boolean>;
|
|
61
|
-
/**
|
|
62
|
-
*
|
|
63
|
-
* @param sessionId - The ID of the session to remove.
|
|
64
|
-
*/
|
|
65
|
-
removeSession(sessionId: string): void;
|
|
66
|
-
getClient(): Client;
|
|
67
|
-
getAPIKey(): string;
|
|
68
|
-
}
|
package/dist/src/agent-bay.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.AgentBay = void 0;
|
|
40
|
-
const session_1 = require("./session");
|
|
41
|
-
const context_1 = require("./context");
|
|
42
|
-
const exceptions_1 = require("./exceptions");
|
|
43
|
-
const $_client = __importStar(require("./api"));
|
|
44
|
-
const openapi_core_1 = require("@alicloud/openapi-core");
|
|
45
|
-
const client_1 = __importDefault(require("./api/client"));
|
|
46
|
-
const model_1 = require("./api/models/model");
|
|
47
|
-
const config_1 = require("./config");
|
|
48
|
-
require("dotenv/config");
|
|
49
|
-
const logger_1 = require("./utils/logger");
|
|
50
|
-
/**
|
|
51
|
-
* Main class for interacting with the AgentBay cloud runtime environment.
|
|
52
|
-
*/
|
|
53
|
-
class AgentBay {
|
|
54
|
-
/**
|
|
55
|
-
* Initialize the AgentBay client.
|
|
56
|
-
*
|
|
57
|
-
* @param options - Configuration options
|
|
58
|
-
* @param options.apiKey - API key for authentication. If not provided, will look for AGENTBAY_API_KEY environment variable.
|
|
59
|
-
*/
|
|
60
|
-
constructor(options = {}) {
|
|
61
|
-
this.sessions = new Map();
|
|
62
|
-
this.apiKey = options.apiKey || process.env.AGENTBAY_API_KEY || '';
|
|
63
|
-
if (!this.apiKey) {
|
|
64
|
-
throw new exceptions_1.AuthenticationError('API key is required. Provide it as a parameter or set the AGENTBAY_API_KEY environment variable.');
|
|
65
|
-
}
|
|
66
|
-
// Load configuration
|
|
67
|
-
const configData = (0, config_1.loadConfig)();
|
|
68
|
-
this.regionId = configData.region_id;
|
|
69
|
-
this.endpoint = configData.endpoint;
|
|
70
|
-
const config = new openapi_core_1.$OpenApiUtil.Config({
|
|
71
|
-
regionId: this.regionId,
|
|
72
|
-
endpoint: this.endpoint
|
|
73
|
-
});
|
|
74
|
-
config.readTimeout = configData.timeout_ms;
|
|
75
|
-
config.connectTimeout = configData.timeout_ms;
|
|
76
|
-
try {
|
|
77
|
-
this.client = new client_1.default(config);
|
|
78
|
-
// Initialize context service
|
|
79
|
-
this.context = new context_1.ContextService(this);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
(0, logger_1.logError)(`Failed to constructor:`, error);
|
|
83
|
-
throw new exceptions_1.AuthenticationError(`Failed to constructor: ${error}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Create a new session in the AgentBay cloud environment.
|
|
88
|
-
*
|
|
89
|
-
* @param options - Optional parameters for creating the session
|
|
90
|
-
* @param options.contextId - ID of the context to bind to the session
|
|
91
|
-
* @param options.labels - Custom labels for the session
|
|
92
|
-
* @returns A new Session object.
|
|
93
|
-
*/
|
|
94
|
-
async create(options = {}) {
|
|
95
|
-
try {
|
|
96
|
-
const createSessionRequest = new $_client.CreateMcpSessionRequest({
|
|
97
|
-
authorization: "Bearer " + this.apiKey,
|
|
98
|
-
imageId: options.imageId
|
|
99
|
-
});
|
|
100
|
-
// Add context_id if provided
|
|
101
|
-
if (options.contextId) {
|
|
102
|
-
createSessionRequest.contextId = options.contextId;
|
|
103
|
-
}
|
|
104
|
-
// Add labels if provided
|
|
105
|
-
if (options.labels) {
|
|
106
|
-
createSessionRequest.labels = JSON.stringify(options.labels);
|
|
107
|
-
}
|
|
108
|
-
// Log API request
|
|
109
|
-
(0, logger_1.log)("API Call: CreateMcpSession");
|
|
110
|
-
(0, logger_1.log)(`Request: ${options.contextId ? `ContextId=${options.contextId}, ` : ''}${options.labels ? `Labels=${JSON.stringify(options.labels)}, ` : ''}${options.imageId ? `ImageId=${options.imageId}` : ''}`);
|
|
111
|
-
const response = await this.client.createMcpSession(createSessionRequest);
|
|
112
|
-
// Log API response
|
|
113
|
-
(0, logger_1.log)(`Response from CreateMcpSession:`, response.body);
|
|
114
|
-
const sessionId = response.body?.data?.sessionId;
|
|
115
|
-
if (!sessionId) {
|
|
116
|
-
throw new exceptions_1.APIError('Invalid session ID in response');
|
|
117
|
-
}
|
|
118
|
-
// ResourceUrl is optional in CreateMcpSession response
|
|
119
|
-
const resourceUrl = response.body?.data?.resourceUrl;
|
|
120
|
-
const session = new session_1.Session(this, sessionId);
|
|
121
|
-
if (resourceUrl) {
|
|
122
|
-
session.resourceUrl = resourceUrl;
|
|
123
|
-
}
|
|
124
|
-
this.sessions.set(session.sessionId, session);
|
|
125
|
-
return session;
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
(0, logger_1.logError)("Error calling CreateMcpSession:", error);
|
|
129
|
-
throw new exceptions_1.APIError(`Failed to create session: ${error}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* List all available sessions.
|
|
134
|
-
*
|
|
135
|
-
* @returns A list of session objects.
|
|
136
|
-
*/
|
|
137
|
-
list() {
|
|
138
|
-
return Array.from(this.sessions.values());
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* List sessions filtered by the provided labels.
|
|
142
|
-
* It returns sessions that match all the specified labels.
|
|
143
|
-
*
|
|
144
|
-
* @param labels - The labels to filter by.
|
|
145
|
-
* @returns A list of session objects that match the labels.
|
|
146
|
-
*/
|
|
147
|
-
async listByLabels(labels) {
|
|
148
|
-
try {
|
|
149
|
-
// Convert labels to JSON
|
|
150
|
-
const labelsJSON = JSON.stringify(labels);
|
|
151
|
-
const listSessionRequest = new model_1.ListSessionRequest({
|
|
152
|
-
authorization: `Bearer ${this.apiKey}`,
|
|
153
|
-
labels: labelsJSON
|
|
154
|
-
});
|
|
155
|
-
// Log API request
|
|
156
|
-
(0, logger_1.log)("API Call: ListSession");
|
|
157
|
-
(0, logger_1.log)(`Request: Labels=${labelsJSON}`);
|
|
158
|
-
const response = await this.client.listSession(listSessionRequest);
|
|
159
|
-
// Log API response
|
|
160
|
-
(0, logger_1.log)(`Response from ListSession:`, response.body);
|
|
161
|
-
const sessions = [];
|
|
162
|
-
if (response.body?.data) {
|
|
163
|
-
for (const sessionData of response.body.data) {
|
|
164
|
-
if (sessionData.sessionId) {
|
|
165
|
-
const session = new session_1.Session(this, sessionData.sessionId);
|
|
166
|
-
sessions.push(session);
|
|
167
|
-
// Also store in the local cache
|
|
168
|
-
this.sessions.set(sessionData.sessionId, session);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return sessions;
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
(0, logger_1.logError)("Error calling ListSession:", error);
|
|
176
|
-
throw new exceptions_1.APIError(`Failed to list sessions by labels: ${error}`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Delete a session by ID.
|
|
181
|
-
*
|
|
182
|
-
* @param sessionId - The ID of the session to delete.
|
|
183
|
-
* @returns True if the session was successfully deleted.
|
|
184
|
-
*/
|
|
185
|
-
async delete(session) {
|
|
186
|
-
const getSession = this.sessions.get(session.sessionId);
|
|
187
|
-
if (!getSession) {
|
|
188
|
-
throw new Error(`Session with ID ${session.sessionId} not found`);
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
await session.delete();
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
throw new exceptions_1.APIError(`Failed to delete session: ${error}`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
*
|
|
200
|
-
* @param sessionId - The ID of the session to remove.
|
|
201
|
-
*/
|
|
202
|
-
removeSession(sessionId) {
|
|
203
|
-
this.sessions.delete(sessionId);
|
|
204
|
-
}
|
|
205
|
-
// For internal use by the Session class
|
|
206
|
-
getClient() {
|
|
207
|
-
return this.client;
|
|
208
|
-
}
|
|
209
|
-
getAPIKey() {
|
|
210
|
-
return this.apiKey;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
exports.AgentBay = AgentBay;
|