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
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../../src");
|
|
4
|
-
const test_helpers_1 = require("../utils/test-helpers");
|
|
5
|
-
const logger_1 = require("../../src/utils/logger");
|
|
6
|
-
describe('Context Persistence Integration', () => {
|
|
7
|
-
let agentBay;
|
|
8
|
-
let testContext;
|
|
9
|
-
let testContextName;
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
12
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
13
|
-
// Create a unique context name for testing
|
|
14
|
-
testContextName = `test-context-${(0, test_helpers_1.randomString)()}`;
|
|
15
|
-
// Create a test context
|
|
16
|
-
(0, logger_1.log)(`Creating test context: ${testContextName}`);
|
|
17
|
-
try {
|
|
18
|
-
testContext = await agentBay.context.create(testContextName);
|
|
19
|
-
(0, logger_1.log)(`Test context created with ID: ${testContext.id}`);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
(0, logger_1.log)(`Warning: Error creating test context: ${error}`);
|
|
23
|
-
testContext = null;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
afterEach(async () => {
|
|
27
|
-
// Clean up the test context
|
|
28
|
-
if (testContext) {
|
|
29
|
-
(0, logger_1.log)(`Cleaning up: Deleting test context: ${testContextName}`);
|
|
30
|
-
try {
|
|
31
|
-
await agentBay.context.delete(testContext);
|
|
32
|
-
(0, logger_1.log)('Test context deleted successfully');
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
(0, logger_1.log)(`Warning: Error deleting test context: ${error}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
describe('Context persistence across sessions', () => {
|
|
40
|
-
it('should persist files between sessions in the same context', async () => {
|
|
41
|
-
if (!testContext) {
|
|
42
|
-
(0, logger_1.log)('Skipping test as test context creation failed');
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
// Create first session with the test context
|
|
46
|
-
(0, logger_1.log)('Creating first session with test context...');
|
|
47
|
-
let session1 = null;
|
|
48
|
-
try {
|
|
49
|
-
session1 = await agentBay.create({ contextId: testContext.id });
|
|
50
|
-
(0, logger_1.log)(`First session created with ID: ${session1.sessionId}`);
|
|
51
|
-
// Write a test file in the first session
|
|
52
|
-
if (session1.filesystem && typeof session1.filesystem.writeFile === 'function') {
|
|
53
|
-
const testFilePath = '/tmp/context-test-file.txt';
|
|
54
|
-
const testContent = `Test content created at ${new Date().toISOString()}`;
|
|
55
|
-
(0, logger_1.log)(`Writing test file: ${testFilePath}`);
|
|
56
|
-
await session1.filesystem.writeFile(testFilePath, testContent);
|
|
57
|
-
// Verify the file was written
|
|
58
|
-
const readContent = await session1.filesystem.readFile(testFilePath);
|
|
59
|
-
(0, logger_1.log)(`Verified file content in first session: ${readContent}`);
|
|
60
|
-
expect(readContent).toBe(testContent);
|
|
61
|
-
// Create a second session with the same context
|
|
62
|
-
(0, logger_1.log)('Creating second session with the same test context...');
|
|
63
|
-
let session2 = null;
|
|
64
|
-
try {
|
|
65
|
-
session2 = await agentBay.create({ contextId: testContext.id });
|
|
66
|
-
(0, logger_1.log)(`Second session created with ID: ${session2.sessionId}`);
|
|
67
|
-
// Verify the file exists and has the same content in the second session
|
|
68
|
-
(0, logger_1.log)(`Reading test file in second session: ${testFilePath}`);
|
|
69
|
-
const content2 = await session2.filesystem.readFile(testFilePath);
|
|
70
|
-
(0, logger_1.log)(`File content in second session: ${content2}`);
|
|
71
|
-
// Check if the content matches
|
|
72
|
-
expect(content2).toBe(testContent);
|
|
73
|
-
(0, logger_1.log)('File persistence verified successfully');
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
(0, logger_1.log)(`Error in second session: ${error}`);
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
// Clean up the second session
|
|
81
|
-
if (session2) {
|
|
82
|
-
(0, logger_1.log)('Cleaning up: Deleting second session...');
|
|
83
|
-
try {
|
|
84
|
-
await agentBay.delete(session2);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
(0, logger_1.log)(`Warning: Error deleting second session: ${error}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
(0, logger_1.log)('Skipping test as filesystem.writeFile is not available');
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
(0, logger_1.log)(`Error in first session: ${error}`);
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
finally {
|
|
101
|
-
// Clean up the first session
|
|
102
|
-
if (session1) {
|
|
103
|
-
(0, logger_1.log)('Cleaning up: Deleting first session...');
|
|
104
|
-
try {
|
|
105
|
-
await agentBay.delete(session1);
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
(0, logger_1.log)(`Warning: Error deleting first session: ${error}`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
describe('File isolation between contexts', () => {
|
|
115
|
-
it('should isolate files between different contexts', async () => {
|
|
116
|
-
if (!testContext) {
|
|
117
|
-
(0, logger_1.log)('Skipping test as test context creation failed');
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
// Create a second test context
|
|
121
|
-
const secondContextName = `test-context-2-${(0, test_helpers_1.randomString)()}`;
|
|
122
|
-
(0, logger_1.log)(`Creating second test context: ${secondContextName}`);
|
|
123
|
-
let secondContext = null;
|
|
124
|
-
try {
|
|
125
|
-
secondContext = await agentBay.context.create(secondContextName);
|
|
126
|
-
(0, logger_1.log)(`Second test context created with ID: ${secondContext.id}`);
|
|
127
|
-
// Create first session with the first test context
|
|
128
|
-
(0, logger_1.log)('Creating session with first test context...');
|
|
129
|
-
let session1 = null;
|
|
130
|
-
try {
|
|
131
|
-
session1 = await agentBay.create({ contextId: testContext.id });
|
|
132
|
-
(0, logger_1.log)(`First session created with ID: ${session1.sessionId}`);
|
|
133
|
-
// Write a test file in the first session
|
|
134
|
-
if (session1.filesystem && typeof session1.filesystem.writeFile === 'function') {
|
|
135
|
-
const testFilePath = '/tmp/context-isolation-test-file.txt';
|
|
136
|
-
const testContent = `Test content for isolation test created at ${new Date().toISOString()}`;
|
|
137
|
-
(0, logger_1.log)(`Writing test file in first context: ${testFilePath}`);
|
|
138
|
-
await session1.filesystem.writeFile(testFilePath, testContent);
|
|
139
|
-
// Verify the file was written
|
|
140
|
-
const readContent = await session1.filesystem.readFile(testFilePath);
|
|
141
|
-
(0, logger_1.log)(`Verified file content in first context: ${readContent}`);
|
|
142
|
-
expect(readContent).toBe(testContent);
|
|
143
|
-
// Create a second session with the second context
|
|
144
|
-
(0, logger_1.log)('Creating session with second test context...');
|
|
145
|
-
let session2 = null;
|
|
146
|
-
try {
|
|
147
|
-
session2 = await agentBay.create({ contextId: secondContext.id });
|
|
148
|
-
(0, logger_1.log)(`Second session created with ID: ${session2.sessionId}`);
|
|
149
|
-
// Try to read the file in the second context
|
|
150
|
-
(0, logger_1.log)(`Attempting to read test file in second context: ${testFilePath}`);
|
|
151
|
-
try {
|
|
152
|
-
const content2 = await session2.filesystem.readFile(testFilePath);
|
|
153
|
-
(0, logger_1.log)(`File content in second context: ${content2}`);
|
|
154
|
-
// If we get here, the file might exist but should have different content
|
|
155
|
-
// or the API might return an empty string for non-existent files
|
|
156
|
-
if (content2 === testContent) {
|
|
157
|
-
(0, logger_1.log)('Warning: File content is the same in both contexts, isolation may not be working');
|
|
158
|
-
expect(content2).not.toBe(testContent);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
(0, logger_1.log)('File content is different or empty in second context, isolation is working');
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
// If reading the file throws an error, that's also a sign of isolation
|
|
166
|
-
(0, logger_1.log)(`Error reading file in second context: ${error}`);
|
|
167
|
-
(0, logger_1.log)('File isolation verified successfully (file not accessible in second context)');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
(0, logger_1.log)(`Error in second session: ${error}`);
|
|
172
|
-
throw error;
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
// Clean up the second session
|
|
176
|
-
if (session2) {
|
|
177
|
-
(0, logger_1.log)('Cleaning up: Deleting second session...');
|
|
178
|
-
try {
|
|
179
|
-
await agentBay.delete(session2);
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
(0, logger_1.log)(`Warning: Error deleting second session: ${error}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
(0, logger_1.log)('Skipping test as filesystem.writeFile is not available');
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
catch (error) {
|
|
192
|
-
(0, logger_1.log)(`Error in first session: ${error}`);
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
finally {
|
|
196
|
-
// Clean up the first session
|
|
197
|
-
if (session1) {
|
|
198
|
-
(0, logger_1.log)('Cleaning up: Deleting first session...');
|
|
199
|
-
try {
|
|
200
|
-
await agentBay.delete(session1);
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
(0, logger_1.log)(`Warning: Error deleting first session: ${error}`);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
(0, logger_1.log)(`Error creating second test context: ${error}`);
|
|
210
|
-
throw error;
|
|
211
|
-
}
|
|
212
|
-
finally {
|
|
213
|
-
// Clean up the second test context
|
|
214
|
-
if (secondContext) {
|
|
215
|
-
(0, logger_1.log)(`Cleaning up: Deleting second test context: ${secondContextName}`);
|
|
216
|
-
try {
|
|
217
|
-
await agentBay.context.delete(secondContext);
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
(0, logger_1.log)(`Warning: Error deleting second test context: ${error}`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../../src");
|
|
4
|
-
const test_helpers_1 = require("../utils/test-helpers");
|
|
5
|
-
const logger_1 = require("../../src/utils/logger");
|
|
6
|
-
describe('Context Session Integration', () => {
|
|
7
|
-
let agentBay;
|
|
8
|
-
beforeEach(async () => {
|
|
9
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
10
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
11
|
-
(0, logger_1.log)(`AgentBay client initialized successfully`);
|
|
12
|
-
});
|
|
13
|
-
describe('Context Session Management', () => {
|
|
14
|
-
it('should manage context and session lifecycle correctly', async () => {
|
|
15
|
-
// Step 1: Create a new context
|
|
16
|
-
const contextName = `test-context-${Date.now()}`;
|
|
17
|
-
(0, logger_1.log)(`Creating new context with name: ${contextName}`);
|
|
18
|
-
const context = await agentBay.context.create(contextName);
|
|
19
|
-
if (!context) {
|
|
20
|
-
throw new Error('Failed to create context');
|
|
21
|
-
}
|
|
22
|
-
(0, logger_1.log)(`Context created successfully - ID: ${context.id}, Name: ${context.name}, State: ${context.state}`);
|
|
23
|
-
expect(context.id).toBeDefined();
|
|
24
|
-
expect(context.name).toBe(contextName);
|
|
25
|
-
try {
|
|
26
|
-
// Step 2: Create a session with the context ID (expect success)
|
|
27
|
-
(0, logger_1.log)('Step 2: Creating first session with context ID...');
|
|
28
|
-
const session1 = await agentBay.create({ contextId: context.id });
|
|
29
|
-
(0, logger_1.log)(`Session created successfully with ID: ${session1.sessionId}`);
|
|
30
|
-
// Step 3: Get the context directly and verify that its status is "in-use"
|
|
31
|
-
(0, logger_1.log)('Step 3: Checking context status after session creation...');
|
|
32
|
-
// Wait a moment for the system to update the context status
|
|
33
|
-
await (0, test_helpers_1.wait)(2000);
|
|
34
|
-
const updatedContext = await agentBay.context.get(contextName);
|
|
35
|
-
if (!updatedContext) {
|
|
36
|
-
throw new Error('Failed to retrieve updated context');
|
|
37
|
-
}
|
|
38
|
-
(0, logger_1.log)(`Retrieved context - ID: ${updatedContext.id}, Name: ${updatedContext.name}, State: ${updatedContext.state}`);
|
|
39
|
-
expect(updatedContext.state).toBe('in-use');
|
|
40
|
-
(0, logger_1.log)('Context state is correctly set to "in-use"');
|
|
41
|
-
// Step 4: Try to create another session with the same context_id (expect failure)
|
|
42
|
-
(0, logger_1.log)('Step 4: Attempting to create a second session with the same context ID...');
|
|
43
|
-
try {
|
|
44
|
-
const session2 = await agentBay.create({ contextId: context.id });
|
|
45
|
-
// If somehow it succeeds (which shouldn't happen), make sure to clean it up
|
|
46
|
-
(0, logger_1.log)(`WARNING: Unexpectedly succeeded in creating second session with ID: ${session2.sessionId}`);
|
|
47
|
-
await session2.delete();
|
|
48
|
-
// This should fail the test
|
|
49
|
-
expect(false).toBe(true);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
(0, logger_1.log)(`As expected, failed to create second session with same context ID: ${error}`);
|
|
53
|
-
// This is the expected behavior
|
|
54
|
-
}
|
|
55
|
-
// Step 5: Release the first session
|
|
56
|
-
(0, logger_1.log)('Step 5: Releasing the first session...');
|
|
57
|
-
await session1.delete();
|
|
58
|
-
(0, logger_1.log)('First session released successfully');
|
|
59
|
-
// Wait for the system to update the context status
|
|
60
|
-
(0, logger_1.log)('Waiting for context status to update...');
|
|
61
|
-
await (0, test_helpers_1.wait)(3000);
|
|
62
|
-
// Step 6: Get the context directly and verify that its status is "available"
|
|
63
|
-
(0, logger_1.log)('Step 6: Checking context status after session release...');
|
|
64
|
-
const contextAfterRelease = await agentBay.context.get(contextName);
|
|
65
|
-
if (!contextAfterRelease) {
|
|
66
|
-
throw new Error('Failed to retrieve context after release');
|
|
67
|
-
}
|
|
68
|
-
(0, logger_1.log)(`Retrieved context - ID: ${contextAfterRelease.id}, Name: ${contextAfterRelease.name}, State: ${contextAfterRelease.state}`);
|
|
69
|
-
expect(contextAfterRelease.state).toBe('available');
|
|
70
|
-
(0, logger_1.log)('Context state is correctly set to "available"');
|
|
71
|
-
// Step 7: Create another session with the same context_id (expect success)
|
|
72
|
-
(0, logger_1.log)('Step 7: Creating a new session with the same context ID...');
|
|
73
|
-
const session3 = await agentBay.create({ contextId: context.id });
|
|
74
|
-
(0, logger_1.log)(`New session created successfully with ID: ${session3.sessionId}`);
|
|
75
|
-
// Step 8: Clean up by releasing the session
|
|
76
|
-
(0, logger_1.log)('Step 8: Cleaning up - releasing the third session...');
|
|
77
|
-
await session3.delete();
|
|
78
|
-
(0, logger_1.log)('Third session released successfully');
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
// Clean up the context
|
|
82
|
-
(0, logger_1.log)('Cleaning up: Deleting the context...');
|
|
83
|
-
try {
|
|
84
|
-
await agentBay.context.delete(context);
|
|
85
|
-
(0, logger_1.log)(`Context ${context.id} deleted successfully`);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
(0, logger_1.log)(`Warning: Error deleting context: ${error}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
describe('Context Lifecycle', () => {
|
|
94
|
-
it('should manage the complete lifecycle of a context', async () => {
|
|
95
|
-
// Get initial list of contexts for comparison
|
|
96
|
-
(0, logger_1.log)('Getting initial list of contexts...');
|
|
97
|
-
const initialContexts = await agentBay.context.list();
|
|
98
|
-
(0, logger_1.log)(`Found ${initialContexts.length} contexts initially`);
|
|
99
|
-
// Store initial context IDs for comparison
|
|
100
|
-
const initialContextIDs = new Map();
|
|
101
|
-
for (const ctx of initialContexts) {
|
|
102
|
-
initialContextIDs.set(ctx.id, true);
|
|
103
|
-
(0, logger_1.log)(`Initial context: ${ctx.name} (${ctx.id})`);
|
|
104
|
-
}
|
|
105
|
-
// Step 1: Create a new context
|
|
106
|
-
(0, logger_1.log)('Step 1: Creating a new context...');
|
|
107
|
-
const contextName = `test-context-${Date.now()}`;
|
|
108
|
-
const context = await agentBay.context.create(contextName);
|
|
109
|
-
if (!context) {
|
|
110
|
-
throw new Error('Failed to create context');
|
|
111
|
-
}
|
|
112
|
-
(0, logger_1.log)(`Created context: ${context.name} (${context.id})`);
|
|
113
|
-
// Verify the created context has the expected name
|
|
114
|
-
expect(context.name).toBe(contextName);
|
|
115
|
-
expect(context.id).toBeDefined();
|
|
116
|
-
// Store the original context ID for later verification
|
|
117
|
-
const originalContextID = context.id;
|
|
118
|
-
try {
|
|
119
|
-
// Step 2: Get the context we just created
|
|
120
|
-
(0, logger_1.log)('Step 2: Getting the context we just created...');
|
|
121
|
-
const retrievedContext = await agentBay.context.get(contextName);
|
|
122
|
-
if (!retrievedContext) {
|
|
123
|
-
throw new Error('Failed to retrieve context');
|
|
124
|
-
}
|
|
125
|
-
(0, logger_1.log)(`Successfully retrieved context: ${retrievedContext.name} (${retrievedContext.id})`);
|
|
126
|
-
// Verify the retrieved context matches what we created
|
|
127
|
-
expect(retrievedContext.name).toBe(contextName);
|
|
128
|
-
expect(retrievedContext.id).toBe(originalContextID);
|
|
129
|
-
// Step 3: List contexts and verify our new context is in the list
|
|
130
|
-
(0, logger_1.log)('Step 3: Listing all contexts...');
|
|
131
|
-
const allContexts = await agentBay.context.list();
|
|
132
|
-
// Verify the list contains our new context
|
|
133
|
-
let foundInList = false;
|
|
134
|
-
for (const c of allContexts) {
|
|
135
|
-
if (c.id === originalContextID) {
|
|
136
|
-
foundInList = true;
|
|
137
|
-
expect(c.name).toBe(contextName);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
expect(foundInList).toBe(true);
|
|
142
|
-
(0, logger_1.log)('Successfully listed contexts, found our context in the list');
|
|
143
|
-
// Verify the list contains at least one more context than the initial list
|
|
144
|
-
expect(allContexts.length).toBeGreaterThan(initialContexts.length);
|
|
145
|
-
// Step 4: Create a session with the context
|
|
146
|
-
(0, logger_1.log)('Step 4: Creating a session with the context...');
|
|
147
|
-
const session = await agentBay.create({
|
|
148
|
-
contextId: context.id,
|
|
149
|
-
labels: {
|
|
150
|
-
username: 'test-user',
|
|
151
|
-
project: 'test-project'
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
(0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
|
|
155
|
-
try {
|
|
156
|
-
// Step 5: Update the context
|
|
157
|
-
(0, logger_1.log)('Step 5: Updating the context...');
|
|
158
|
-
const updatedName = `updated-${contextName}`;
|
|
159
|
-
context.name = updatedName;
|
|
160
|
-
await agentBay.context.update(context);
|
|
161
|
-
(0, logger_1.log)('Context update reported as successful');
|
|
162
|
-
// Step 6: Verify the update by getting the context again
|
|
163
|
-
(0, logger_1.log)('Step 6: Verifying the update by getting the context again...');
|
|
164
|
-
const retrievedUpdatedContext = await agentBay.context.get(updatedName);
|
|
165
|
-
if (!retrievedUpdatedContext) {
|
|
166
|
-
throw new Error('Failed to retrieve updated context');
|
|
167
|
-
}
|
|
168
|
-
(0, logger_1.log)(`Retrieved updated context: ${retrievedUpdatedContext.name} (${retrievedUpdatedContext.id})`);
|
|
169
|
-
// Verify the retrieved context has the updated name
|
|
170
|
-
expect(retrievedUpdatedContext.name).toBe(updatedName);
|
|
171
|
-
expect(retrievedUpdatedContext.id).toBe(originalContextID);
|
|
172
|
-
// Step 7: List contexts again to verify the update is visible in the list
|
|
173
|
-
(0, logger_1.log)('Step 7: Listing contexts again to verify the update...');
|
|
174
|
-
const updatedContexts = await agentBay.context.list();
|
|
175
|
-
// Find the updated context in the list
|
|
176
|
-
let foundInUpdatedList = false;
|
|
177
|
-
for (const c of updatedContexts) {
|
|
178
|
-
if (c.id === originalContextID) {
|
|
179
|
-
foundInUpdatedList = true;
|
|
180
|
-
expect(c.name).toBe(updatedName);
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
expect(foundInUpdatedList).toBe(true);
|
|
185
|
-
(0, logger_1.log)('Successfully verified context update in the list');
|
|
186
|
-
}
|
|
187
|
-
finally {
|
|
188
|
-
// Clean up the session
|
|
189
|
-
(0, logger_1.log)('Cleaning up: Deleting the session...');
|
|
190
|
-
try {
|
|
191
|
-
await session.delete();
|
|
192
|
-
(0, logger_1.log)('Session successfully deleted');
|
|
193
|
-
}
|
|
194
|
-
catch (error) {
|
|
195
|
-
(0, logger_1.log)(`Warning: Error deleting session: ${error}`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
finally {
|
|
200
|
-
// Clean up the context
|
|
201
|
-
(0, logger_1.log)('Cleaning up: Deleting the context...');
|
|
202
|
-
try {
|
|
203
|
-
await agentBay.context.delete(context);
|
|
204
|
-
(0, logger_1.log)(`Context ${context.id} deleted successfully`);
|
|
205
|
-
// Verify the context is actually deleted
|
|
206
|
-
try {
|
|
207
|
-
const deletedContext = await agentBay.context.get(contextName);
|
|
208
|
-
if (deletedContext && deletedContext.id === originalContextID) {
|
|
209
|
-
(0, logger_1.log)('Error: Context still exists after deletion');
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
catch (error) {
|
|
213
|
-
// This is expected - the context should not exist
|
|
214
|
-
(0, logger_1.log)('Context successfully deleted and no longer exists');
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
catch (error) {
|
|
218
|
-
(0, logger_1.log)(`Warning: Error deleting context: ${error}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|