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.
Files changed (176) hide show
  1. package/README.md +124 -61
  2. package/dist/index.cjs +6621 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.mts +2633 -0
  5. package/dist/index.d.ts +2633 -0
  6. package/dist/index.mjs +6637 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +84 -48
  9. package/dist/src/adb/adb.d.ts +0 -20
  10. package/dist/src/adb/adb.js +0 -57
  11. package/dist/src/adb/index.d.ts +0 -1
  12. package/dist/src/adb/index.js +0 -17
  13. package/dist/src/agent-bay.d.ts +0 -68
  14. package/dist/src/agent-bay.js +0 -213
  15. package/dist/src/api/client.d.ts +0 -191
  16. package/dist/src/api/client.js +0 -629
  17. package/dist/src/api/index.d.ts +0 -4
  18. package/dist/src/api/index.js +0 -26
  19. package/dist/src/api/models/CallMcpToolRequest.d.ts +0 -21
  20. package/dist/src/api/models/CallMcpToolRequest.js +0 -71
  21. package/dist/src/api/models/CallMcpToolResponse.d.ts +0 -19
  22. package/dist/src/api/models/CallMcpToolResponse.js +0 -68
  23. package/dist/src/api/models/CallMcpToolResponseBody.d.ts +0 -19
  24. package/dist/src/api/models/CallMcpToolResponseBody.js +0 -67
  25. package/dist/src/api/models/CreateMcpSessionRequest.d.ts +0 -19
  26. package/dist/src/api/models/CreateMcpSessionRequest.js +0 -67
  27. package/dist/src/api/models/CreateMcpSessionResponse.d.ts +0 -19
  28. package/dist/src/api/models/CreateMcpSessionResponse.js +0 -68
  29. package/dist/src/api/models/CreateMcpSessionResponseBody.d.ts +0 -20
  30. package/dist/src/api/models/CreateMcpSessionResponseBody.js +0 -71
  31. package/dist/src/api/models/CreateMcpSessionResponseBodyData.d.ts +0 -19
  32. package/dist/src/api/models/CreateMcpSessionResponseBodyData.js +0 -67
  33. package/dist/src/api/models/DeleteContextRequest.d.ts +0 -15
  34. package/dist/src/api/models/DeleteContextRequest.js +0 -59
  35. package/dist/src/api/models/DeleteContextResponse.d.ts +0 -19
  36. package/dist/src/api/models/DeleteContextResponse.js +0 -68
  37. package/dist/src/api/models/DeleteContextResponseBody.d.ts +0 -18
  38. package/dist/src/api/models/DeleteContextResponseBody.js +0 -65
  39. package/dist/src/api/models/GetContextRequest.d.ts +0 -16
  40. package/dist/src/api/models/GetContextRequest.js +0 -61
  41. package/dist/src/api/models/GetContextResponse.d.ts +0 -19
  42. package/dist/src/api/models/GetContextResponse.js +0 -68
  43. package/dist/src/api/models/GetContextResponseBody.d.ts +0 -20
  44. package/dist/src/api/models/GetContextResponseBody.js +0 -71
  45. package/dist/src/api/models/GetContextResponseBodyData.d.ts +0 -19
  46. package/dist/src/api/models/GetContextResponseBodyData.js +0 -67
  47. package/dist/src/api/models/GetLabelRequest.d.ts +0 -17
  48. package/dist/src/api/models/GetLabelRequest.js +0 -63
  49. package/dist/src/api/models/GetLabelResponse.d.ts +0 -19
  50. package/dist/src/api/models/GetLabelResponse.js +0 -68
  51. package/dist/src/api/models/GetLabelResponseBody.d.ts +0 -23
  52. package/dist/src/api/models/GetLabelResponseBody.js +0 -77
  53. package/dist/src/api/models/GetLabelResponseBodyData.d.ts +0 -14
  54. package/dist/src/api/models/GetLabelResponseBodyData.js +0 -57
  55. package/dist/src/api/models/GetLinkRequest.d.ts +0 -15
  56. package/dist/src/api/models/GetLinkRequest.js +0 -59
  57. package/dist/src/api/models/GetLinkResponse.d.ts +0 -19
  58. package/dist/src/api/models/GetLinkResponse.js +0 -68
  59. package/dist/src/api/models/GetLinkResponseBody.d.ts +0 -19
  60. package/dist/src/api/models/GetLinkResponseBody.js +0 -67
  61. package/dist/src/api/models/GetMcpResourceRequest.d.ts +0 -15
  62. package/dist/src/api/models/GetMcpResourceRequest.js +0 -59
  63. package/dist/src/api/models/GetMcpResourceResponse.d.ts +0 -19
  64. package/dist/src/api/models/GetMcpResourceResponse.js +0 -68
  65. package/dist/src/api/models/GetMcpResourceResponseBody.d.ts +0 -20
  66. package/dist/src/api/models/GetMcpResourceResponseBody.js +0 -71
  67. package/dist/src/api/models/GetMcpResourceResponseBodyData.d.ts +0 -17
  68. package/dist/src/api/models/GetMcpResourceResponseBodyData.js +0 -65
  69. package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.d.ts +0 -18
  70. package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.js +0 -65
  71. package/dist/src/api/models/ListContextsRequest.d.ts +0 -16
  72. package/dist/src/api/models/ListContextsRequest.js +0 -61
  73. package/dist/src/api/models/ListContextsResponse.d.ts +0 -19
  74. package/dist/src/api/models/ListContextsResponse.js +0 -68
  75. package/dist/src/api/models/ListContextsResponseBody.d.ts +0 -23
  76. package/dist/src/api/models/ListContextsResponseBody.js +0 -77
  77. package/dist/src/api/models/ListContextsResponseBodyData.d.ts +0 -19
  78. package/dist/src/api/models/ListContextsResponseBodyData.js +0 -67
  79. package/dist/src/api/models/ListSessionRequest.d.ts +0 -17
  80. package/dist/src/api/models/ListSessionRequest.js +0 -63
  81. package/dist/src/api/models/ListSessionResponse.d.ts +0 -19
  82. package/dist/src/api/models/ListSessionResponse.js +0 -68
  83. package/dist/src/api/models/ListSessionResponseBody.d.ts +0 -23
  84. package/dist/src/api/models/ListSessionResponseBody.js +0 -77
  85. package/dist/src/api/models/ListSessionResponseBodyData.d.ts +0 -14
  86. package/dist/src/api/models/ListSessionResponseBodyData.js +0 -57
  87. package/dist/src/api/models/ModifyContextRequest.d.ts +0 -16
  88. package/dist/src/api/models/ModifyContextRequest.js +0 -61
  89. package/dist/src/api/models/ModifyContextResponse.d.ts +0 -19
  90. package/dist/src/api/models/ModifyContextResponse.js +0 -68
  91. package/dist/src/api/models/ModifyContextResponseBody.d.ts +0 -18
  92. package/dist/src/api/models/ModifyContextResponseBody.js +0 -65
  93. package/dist/src/api/models/ReleaseMcpSessionRequest.d.ts +0 -15
  94. package/dist/src/api/models/ReleaseMcpSessionRequest.js +0 -59
  95. package/dist/src/api/models/ReleaseMcpSessionResponse.d.ts +0 -19
  96. package/dist/src/api/models/ReleaseMcpSessionResponse.js +0 -68
  97. package/dist/src/api/models/ReleaseMcpSessionResponseBody.d.ts +0 -18
  98. package/dist/src/api/models/ReleaseMcpSessionResponseBody.js +0 -65
  99. package/dist/src/api/models/SetLabelRequest.d.ts +0 -16
  100. package/dist/src/api/models/SetLabelRequest.js +0 -61
  101. package/dist/src/api/models/SetLabelResponse.d.ts +0 -19
  102. package/dist/src/api/models/SetLabelResponse.js +0 -68
  103. package/dist/src/api/models/SetLabelResponseBody.d.ts +0 -18
  104. package/dist/src/api/models/SetLabelResponseBody.js +0 -65
  105. package/dist/src/api/models/model.d.ts +0 -43
  106. package/dist/src/api/models/model.js +0 -89
  107. package/dist/src/application/application.d.ts +0 -88
  108. package/dist/src/application/application.js +0 -172
  109. package/dist/src/application/index.d.ts +0 -1
  110. package/dist/src/application/index.js +0 -17
  111. package/dist/src/command/command.d.ts +0 -43
  112. package/dist/src/command/command.js +0 -120
  113. package/dist/src/command/index.d.ts +0 -1
  114. package/dist/src/command/index.js +0 -17
  115. package/dist/src/config.d.ts +0 -15
  116. package/dist/src/config.js +0 -114
  117. package/dist/src/context.d.ts +0 -87
  118. package/dist/src/context.js +0 -208
  119. package/dist/src/exceptions.d.ts +0 -30
  120. package/dist/src/exceptions.js +0 -58
  121. package/dist/src/filesystem/filesystem.d.ts +0 -109
  122. package/dist/src/filesystem/filesystem.js +0 -245
  123. package/dist/src/filesystem/index.d.ts +0 -1
  124. package/dist/src/filesystem/index.js +0 -17
  125. package/dist/src/index.d.ts +0 -10
  126. package/dist/src/index.js +0 -32
  127. package/dist/src/oss/index.d.ts +0 -1
  128. package/dist/src/oss/index.js +0 -5
  129. package/dist/src/oss/oss.d.ts +0 -80
  130. package/dist/src/oss/oss.js +0 -233
  131. package/dist/src/session.d.ts +0 -99
  132. package/dist/src/session.js +0 -226
  133. package/dist/src/ui/index.d.ts +0 -1
  134. package/dist/src/ui/index.js +0 -17
  135. package/dist/src/ui/ui.d.ts +0 -95
  136. package/dist/src/ui/ui.js +0 -206
  137. package/dist/src/utils/logger.d.ts +0 -15
  138. package/dist/src/utils/logger.js +0 -48
  139. package/dist/src/window/index.d.ts +0 -1
  140. package/dist/src/window/index.js +0 -17
  141. package/dist/src/window/window.d.ts +0 -109
  142. package/dist/src/window/window.js +0 -220
  143. package/dist/tests/agent-bay.test.d.ts +0 -1
  144. package/dist/tests/agent-bay.test.js +0 -366
  145. package/dist/tests/integration/context-persistence.test.d.ts +0 -1
  146. package/dist/tests/integration/context-persistence.test.js +0 -226
  147. package/dist/tests/integration/context-session.test.d.ts +0 -1
  148. package/dist/tests/integration/context-session.test.js +0 -223
  149. package/dist/tests/integration/window-operations.test.d.ts +0 -1
  150. package/dist/tests/integration/window-operations.test.js +0 -228
  151. package/dist/tests/unit/adb.test.d.ts +0 -1
  152. package/dist/tests/unit/adb.test.js +0 -60
  153. package/dist/tests/unit/agent-bay.test.d.ts +0 -1
  154. package/dist/tests/unit/agent-bay.test.js +0 -182
  155. package/dist/tests/unit/application.test.d.ts +0 -1
  156. package/dist/tests/unit/application.test.js +0 -260
  157. package/dist/tests/unit/command.test.d.ts +0 -1
  158. package/dist/tests/unit/command.test.js +0 -252
  159. package/dist/tests/unit/context.test.d.ts +0 -1
  160. package/dist/tests/unit/context.test.js +0 -199
  161. package/dist/tests/unit/filesystem.test.d.ts +0 -1
  162. package/dist/tests/unit/filesystem.test.js +0 -493
  163. package/dist/tests/unit/oss.test.d.ts +0 -1
  164. package/dist/tests/unit/oss.test.js +0 -243
  165. package/dist/tests/unit/session-labels.test.d.ts +0 -1
  166. package/dist/tests/unit/session-labels.test.js +0 -138
  167. package/dist/tests/unit/session-params.test.d.ts +0 -1
  168. package/dist/tests/unit/session-params.test.js +0 -78
  169. package/dist/tests/unit/session.test.d.ts +0 -1
  170. package/dist/tests/unit/session.test.js +0 -204
  171. package/dist/tests/unit/ui.test.d.ts +0 -1
  172. package/dist/tests/unit/ui.test.js +0 -158
  173. package/dist/tests/unit/window.test.d.ts +0 -1
  174. package/dist/tests/unit/window.test.js +0 -331
  175. package/dist/tests/utils/test-helpers.d.ts +0 -35
  176. package/dist/tests/utils/test-helpers.js +0 -79
@@ -1,208 +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
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ContextService = exports.Context = void 0;
37
- const exceptions_1 = require("./exceptions");
38
- const $_client = __importStar(require("./api"));
39
- const logger_1 = require("./utils/logger");
40
- /**
41
- * Represents a persistent storage context in the AgentBay cloud environment.
42
- */
43
- class Context {
44
- /**
45
- * Initialize a Context object.
46
- *
47
- * @param id - The unique identifier of the context.
48
- * @param name - The name of the context.
49
- * @param state - The current state of the context.
50
- * @param createdAt - Date and time when the Context was created.
51
- * @param lastUsedAt - Date and time when the Context was last used.
52
- * @param osType - The operating system type this context is bound to.
53
- */
54
- constructor(id, name, state = 'available', createdAt, lastUsedAt, osType) {
55
- this.id = id;
56
- this.name = name;
57
- this.state = state;
58
- this.createdAt = createdAt;
59
- this.lastUsedAt = lastUsedAt;
60
- this.osType = osType;
61
- }
62
- }
63
- exports.Context = Context;
64
- /**
65
- * Provides methods to manage persistent contexts in the AgentBay cloud environment.
66
- */
67
- class ContextService {
68
- /**
69
- * Initialize the ContextService.
70
- *
71
- * @param agentBay - The AgentBay instance.
72
- */
73
- constructor(agentBay) {
74
- this.agentBay = agentBay;
75
- }
76
- /**
77
- * Lists all available contexts.
78
- *
79
- * @returns A list of Context objects.
80
- */
81
- async list() {
82
- try {
83
- const request = new $_client.ListContextsRequest({
84
- authorization: `Bearer ${this.agentBay.getAPIKey()}`
85
- });
86
- // Log API request
87
- (0, logger_1.log)("API Call: ListContexts");
88
- (0, logger_1.log)("Request: No parameters");
89
- const response = await this.agentBay.getClient().listContexts(request);
90
- // Log API response
91
- (0, logger_1.log)(`Response from ListContexts:`, response.body);
92
- const contexts = [];
93
- if (response.body?.data) {
94
- for (const contextData of response.body.data) {
95
- contexts.push(new Context(contextData.id || '', contextData.name || '', contextData.state || 'available', contextData.createTime, contextData.lastUsedTime, contextData.osType));
96
- }
97
- }
98
- return contexts;
99
- }
100
- catch (error) {
101
- (0, logger_1.logError)("Error calling ListContexts:", error);
102
- throw new exceptions_1.APIError(`Failed to list contexts: ${error}`);
103
- }
104
- }
105
- /**
106
- * Gets a context by name. Optionally creates it if it doesn't exist.
107
- *
108
- * @param name - The name of the context to get.
109
- * @param create - Whether to create the context if it doesn't exist.
110
- * @returns The Context object if found or created, null if not found and create is false.
111
- */
112
- async get(name, create = false) {
113
- try {
114
- const request = new $_client.GetContextRequest({
115
- name: name,
116
- allowCreate: create ? 'true' : 'false',
117
- authorization: `Bearer ${this.agentBay.getAPIKey()}`
118
- });
119
- // Log API request
120
- (0, logger_1.log)("API Call: GetContext");
121
- (0, logger_1.log)(`Request: Name=${name}, AllowCreate=${create}`);
122
- const response = await this.agentBay.getClient().getContext(request);
123
- // Log API response
124
- (0, logger_1.log)(`Response from GetContext:`, response.body);
125
- const contextId = response.body?.data?.id;
126
- if (!contextId) {
127
- return null;
128
- }
129
- // Get the full context details
130
- const contexts = await this.list();
131
- for (const context of contexts) {
132
- if (context.id === contextId) {
133
- return context;
134
- }
135
- }
136
- // If we couldn't find the context in the list, create a basic one
137
- return new Context(contextId, name);
138
- }
139
- catch (error) {
140
- (0, logger_1.logError)("Error calling GetContext:", error);
141
- throw new exceptions_1.APIError(`Failed to get context ${name}: ${error}`);
142
- }
143
- }
144
- /**
145
- * Creates a new context with the given name.
146
- *
147
- * @param name - The name for the new context.
148
- * @returns The created Context object.
149
- */
150
- async create(name) {
151
- const context = await this.get(name, true);
152
- if (!context) {
153
- throw new exceptions_1.APIError(`Failed to create context ${name}`);
154
- }
155
- return context;
156
- }
157
- /**
158
- * Updates the specified context.
159
- *
160
- * @param context - The Context object to update.
161
- * @returns The updated Context object.
162
- */
163
- async update(context) {
164
- try {
165
- const request = new $_client.ModifyContextRequest({
166
- id: context.id,
167
- name: context.name,
168
- authorization: `Bearer ${this.agentBay.getAPIKey()}`
169
- });
170
- // Log API request
171
- (0, logger_1.log)("API Call: ModifyContext");
172
- (0, logger_1.log)(`Request: Id=${context.id}, Name=${context.name}`);
173
- const response = await this.agentBay.getClient().modifyContext(request);
174
- // Log API response
175
- (0, logger_1.log)(`Response from ModifyContext:`, response.body);
176
- // Return the updated context
177
- return context;
178
- }
179
- catch (error) {
180
- (0, logger_1.logError)("Error calling ModifyContext:", error);
181
- throw new exceptions_1.APIError(`Failed to update context ${context.id}: ${error}`);
182
- }
183
- }
184
- /**
185
- * Deletes the specified context.
186
- *
187
- * @param context - The Context object to delete.
188
- */
189
- async delete(context) {
190
- try {
191
- const request = new $_client.DeleteContextRequest({
192
- id: context.id,
193
- authorization: `Bearer ${this.agentBay.getAPIKey()}`
194
- });
195
- // Log API request
196
- (0, logger_1.log)("API Call: DeleteContext");
197
- (0, logger_1.log)(`Request: Id=${context.id}`);
198
- const response = await this.agentBay.getClient().deleteContext(request);
199
- // Log API response
200
- (0, logger_1.log)(`Response from DeleteContext:`, response.body);
201
- }
202
- catch (error) {
203
- (0, logger_1.logError)("Error calling DeleteContext:", error);
204
- throw new exceptions_1.APIError(`Failed to delete context ${context.id}: ${error}`);
205
- }
206
- }
207
- }
208
- exports.ContextService = ContextService;
@@ -1,30 +0,0 @@
1
- /**
2
- * Base exception for all AgentBay errors.
3
- */
4
- export declare class AgentBayError extends Error {
5
- constructor(message: string);
6
- }
7
- /**
8
- * Raised when there is an authentication error.
9
- */
10
- export declare class AuthenticationError extends AgentBayError {
11
- constructor(message: string);
12
- }
13
- /**
14
- * Raised when there is an error with the API.
15
- */
16
- export declare class APIError extends AgentBayError {
17
- constructor(message: string);
18
- }
19
- /**
20
- * Raised when there is an error with file operations.
21
- */
22
- export declare class FileError extends AgentBayError {
23
- constructor(message: string);
24
- }
25
- /**
26
- * Raised when there is an error with command execution.
27
- */
28
- export declare class CommandError extends AgentBayError {
29
- constructor(message: string);
30
- }
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandError = exports.FileError = exports.APIError = exports.AuthenticationError = exports.AgentBayError = void 0;
4
- /**
5
- * Base exception for all AgentBay errors.
6
- */
7
- class AgentBayError extends Error {
8
- constructor(message) {
9
- super(message);
10
- this.name = 'AgentBayError';
11
- Object.setPrototypeOf(this, AgentBayError.prototype);
12
- }
13
- }
14
- exports.AgentBayError = AgentBayError;
15
- /**
16
- * Raised when there is an authentication error.
17
- */
18
- class AuthenticationError extends AgentBayError {
19
- constructor(message) {
20
- super(message);
21
- this.name = 'AuthenticationError';
22
- Object.setPrototypeOf(this, AuthenticationError.prototype);
23
- }
24
- }
25
- exports.AuthenticationError = AuthenticationError;
26
- /**
27
- * Raised when there is an error with the API.
28
- */
29
- class APIError extends AgentBayError {
30
- constructor(message) {
31
- super(message);
32
- this.name = 'APIError';
33
- Object.setPrototypeOf(this, APIError.prototype);
34
- }
35
- }
36
- exports.APIError = APIError;
37
- /**
38
- * Raised when there is an error with file operations.
39
- */
40
- class FileError extends AgentBayError {
41
- constructor(message) {
42
- super(message);
43
- this.name = 'FileError';
44
- Object.setPrototypeOf(this, FileError.prototype);
45
- }
46
- }
47
- exports.FileError = FileError;
48
- /**
49
- * Raised when there is an error with command execution.
50
- */
51
- class CommandError extends AgentBayError {
52
- constructor(message) {
53
- super(message);
54
- this.name = 'CommandError';
55
- Object.setPrototypeOf(this, CommandError.prototype);
56
- }
57
- }
58
- exports.CommandError = CommandError;
@@ -1,109 +0,0 @@
1
- import { Session } from '../session';
2
- /**
3
- * Handles file operations in the AgentBay cloud environment.
4
- */
5
- export declare class FileSystem {
6
- private session;
7
- private client;
8
- private baseUrl;
9
- /**
10
- * Initialize a FileSystem object.
11
- *
12
- * @param session - The Session instance that this FileSystem belongs to.
13
- */
14
- constructor(session: Session);
15
- /**
16
- * Helper method to call MCP tools and handle common response processing
17
- *
18
- * @param toolName - Name of the MCP tool to call
19
- * @param args - Arguments to pass to the tool
20
- * @param defaultErrorMsg - Default error message if specific error details are not available
21
- * @returns A CallMcpToolResult with the response data
22
- * @throws APIError if the call fails
23
- */
24
- private callMcpTool;
25
- /**
26
- * Creates a new directory at the specified path.
27
- *
28
- * @param path - Path to the directory to create.
29
- * @returns The content field from the API response
30
- * @throws APIError if the operation fails.
31
- */
32
- createDirectory(path: string): Promise<any>;
33
- /**
34
- * Edits a file by replacing occurrences of oldText with newText.
35
- *
36
- * @param path - Path to the file to edit.
37
- * @param edits - Array of edit operations, each containing oldText and newText.
38
- * @param dryRun - Optional: If true, preview changes without applying them.
39
- * @returns The content field from the API response
40
- * @throws APIError if the operation fails.
41
- */
42
- editFile(path: string, edits: Array<{
43
- oldText: string;
44
- newText: string;
45
- }>, dryRun?: boolean): Promise<any>;
46
- /**
47
- * Gets information about a file or directory.
48
- *
49
- * @param path - Path to the file or directory to inspect.
50
- * @returns The content field from the API response
51
- * @throws APIError if the operation fails.
52
- */
53
- getFileInfo(path: string): Promise<any>;
54
- /**
55
- * Lists the contents of a directory.
56
- *
57
- * @param path - Path to the directory to list.
58
- * @returns The content field from the API response
59
- * @throws APIError if the operation fails.
60
- */
61
- listDirectory(path: string): Promise<any>;
62
- /**
63
- * Moves a file or directory from source to destination.
64
- *
65
- * @param source - Path to the source file or directory.
66
- * @param destination - Path to the destination file or directory.
67
- * @returns The content field from the API response
68
- * @throws APIError if the operation fails.
69
- */
70
- moveFile(source: string, destination: string): Promise<any>;
71
- /**
72
- * Reads the content of a file.
73
- *
74
- * @param path - Path to the file to read.
75
- * @param offset - Optional: Line offset to start reading from.
76
- * @param length - Optional: Number of lines to read. If 0, reads the entire file.
77
- * @returns The content field from the API response
78
- * @throws APIError if the operation fails.
79
- */
80
- readFile(path: string, offset?: number, length?: number): Promise<any>;
81
- /**
82
- * Reads the content of multiple files.
83
- *
84
- * @param paths - Array of file paths to read.
85
- * @returns The content field from the API response
86
- * @throws APIError if the operation fails.
87
- */
88
- readMultipleFiles(paths: string[]): Promise<any>;
89
- /**
90
- * Searches for files in a directory that match a pattern.
91
- *
92
- * @param path - Path to the directory to search in.
93
- * @param pattern - Pattern to search for. Supports glob patterns.
94
- * @param excludePatterns - Optional: Array of patterns to exclude.
95
- * @returns The content field from the API response
96
- * @throws APIError if the operation fails.
97
- */
98
- searchFiles(path: string, pattern: string, excludePatterns?: string[]): Promise<any>;
99
- /**
100
- * Writes content to a file.
101
- *
102
- * @param path - Path to the file to write.
103
- * @param content - Content to write to the file.
104
- * @param mode - Optional: Write mode. One of "overwrite", "append", or "create_new". Default is "overwrite".
105
- * @returns The content field from the API response
106
- * @throws APIError if the operation fails.
107
- */
108
- writeFile(path: string, content: string, mode?: string): Promise<any>;
109
- }
@@ -1,245 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileSystem = void 0;
4
- const exceptions_1 = require("../exceptions");
5
- const model_1 = require("../api/models/model");
6
- const logger_1 = require("../utils/logger");
7
- /**
8
- * Handles file operations in the AgentBay cloud environment.
9
- */
10
- class FileSystem {
11
- /**
12
- * Initialize a FileSystem object.
13
- *
14
- * @param session - The Session instance that this FileSystem belongs to.
15
- */
16
- constructor(session) {
17
- this.session = session;
18
- }
19
- /**
20
- * Helper method to call MCP tools and handle common response processing
21
- *
22
- * @param toolName - Name of the MCP tool to call
23
- * @param args - Arguments to pass to the tool
24
- * @param defaultErrorMsg - Default error message if specific error details are not available
25
- * @returns A CallMcpToolResult with the response data
26
- * @throws APIError if the call fails
27
- */
28
- async callMcpTool(toolName, args, defaultErrorMsg) {
29
- try {
30
- const argsJSON = JSON.stringify(args);
31
- const callToolRequest = new model_1.CallMcpToolRequest({
32
- authorization: `Bearer ${this.session.getAPIKey()}`,
33
- sessionId: this.session.getSessionId(),
34
- name: toolName,
35
- args: argsJSON
36
- });
37
- // Log API request
38
- (0, logger_1.log)(`API Call: CallMcpTool - ${toolName}`);
39
- (0, logger_1.log)(`Request: SessionId=${this.session.getSessionId()}, Args=${argsJSON}`);
40
- const response = await this.session.getClient().callMcpTool(callToolRequest);
41
- // Log API response
42
- (0, logger_1.log)(`Response from CallMcpTool - ${toolName}:`, response.body);
43
- if (!response.body?.data) {
44
- throw new Error('Invalid response data format');
45
- }
46
- // Extract data from response
47
- const data = response.body.data;
48
- // Create result object
49
- const result = {
50
- data,
51
- statusCode: response.statusCode || 0,
52
- isError: false
53
- };
54
- // Check if there's an error in the response
55
- if (data.isError === true) {
56
- result.isError = true;
57
- // Try to extract the error message from the content field
58
- const contentArray = data.content;
59
- if (contentArray && contentArray.length > 0) {
60
- result.content = contentArray;
61
- // Extract error message from the first content item
62
- if (contentArray[0]?.text) {
63
- result.errorMsg = contentArray[0].text;
64
- throw new Error(contentArray[0].text);
65
- }
66
- }
67
- throw new Error(defaultErrorMsg);
68
- }
69
- // Extract content array if it exists
70
- if (Array.isArray(data.content)) {
71
- result.content = data.content;
72
- }
73
- return result;
74
- }
75
- catch (error) {
76
- (0, logger_1.logError)(`Error calling CallMcpTool - ${toolName}:`, error);
77
- throw new exceptions_1.APIError(`Failed to call ${toolName}: ${error}`);
78
- }
79
- }
80
- /**
81
- * Creates a new directory at the specified path.
82
- *
83
- * @param path - Path to the directory to create.
84
- * @returns The content field from the API response
85
- * @throws APIError if the operation fails.
86
- */
87
- async createDirectory(path) {
88
- const args = {
89
- path
90
- };
91
- const result = await this.callMcpTool('create_directory', args, 'Failed to create directory');
92
- // Return the raw content field for the caller to parse
93
- return result.data.content;
94
- }
95
- /**
96
- * Edits a file by replacing occurrences of oldText with newText.
97
- *
98
- * @param path - Path to the file to edit.
99
- * @param edits - Array of edit operations, each containing oldText and newText.
100
- * @param dryRun - Optional: If true, preview changes without applying them.
101
- * @returns The content field from the API response
102
- * @throws APIError if the operation fails.
103
- */
104
- async editFile(path, edits, dryRun = false) {
105
- const args = {
106
- path,
107
- edits,
108
- dryRun
109
- };
110
- const result = await this.callMcpTool('edit_file', args, 'Failed to edit file');
111
- // Return the raw content field for the caller to parse
112
- return result.data.content;
113
- }
114
- /**
115
- * Gets information about a file or directory.
116
- *
117
- * @param path - Path to the file or directory to inspect.
118
- * @returns The content field from the API response
119
- * @throws APIError if the operation fails.
120
- */
121
- async getFileInfo(path) {
122
- const args = {
123
- path
124
- };
125
- const result = await this.callMcpTool('get_file_info', args, 'Failed to get file info');
126
- // Return the raw content field for the caller to parse
127
- return result.data.content;
128
- }
129
- /**
130
- * Lists the contents of a directory.
131
- *
132
- * @param path - Path to the directory to list.
133
- * @returns The content field from the API response
134
- * @throws APIError if the operation fails.
135
- */
136
- async listDirectory(path) {
137
- const args = {
138
- path
139
- };
140
- const result = await this.callMcpTool('list_directory', args, 'Failed to list directory');
141
- // Return the raw content field for the caller to parse
142
- return result.data.content;
143
- }
144
- /**
145
- * Moves a file or directory from source to destination.
146
- *
147
- * @param source - Path to the source file or directory.
148
- * @param destination - Path to the destination file or directory.
149
- * @returns The content field from the API response
150
- * @throws APIError if the operation fails.
151
- */
152
- async moveFile(source, destination) {
153
- const args = {
154
- source,
155
- destination
156
- };
157
- const result = await this.callMcpTool('move_file', args, 'Failed to move file');
158
- // Return the raw content field for the caller to parse
159
- return result.data.content;
160
- }
161
- /**
162
- * Reads the content of a file.
163
- *
164
- * @param path - Path to the file to read.
165
- * @param offset - Optional: Line offset to start reading from.
166
- * @param length - Optional: Number of lines to read. If 0, reads the entire file.
167
- * @returns The content field from the API response
168
- * @throws APIError if the operation fails.
169
- */
170
- async readFile(path, offset = 0, length = 0) {
171
- const args = {
172
- path
173
- };
174
- if (offset > 0) {
175
- args.offset = offset;
176
- }
177
- if (length > 0) {
178
- args.length = length;
179
- }
180
- const result = await this.callMcpTool('read_file', args, 'Failed to read file');
181
- // Return the raw content field for the caller to parse
182
- return result.data.content;
183
- }
184
- /**
185
- * Reads the content of multiple files.
186
- *
187
- * @param paths - Array of file paths to read.
188
- * @returns The content field from the API response
189
- * @throws APIError if the operation fails.
190
- */
191
- async readMultipleFiles(paths) {
192
- const args = {
193
- paths
194
- };
195
- const result = await this.callMcpTool('read_multiple_files', args, 'Failed to read multiple files');
196
- // Return the raw content field for the caller to parse
197
- return result.data.content;
198
- }
199
- /**
200
- * Searches for files in a directory that match a pattern.
201
- *
202
- * @param path - Path to the directory to search in.
203
- * @param pattern - Pattern to search for. Supports glob patterns.
204
- * @param excludePatterns - Optional: Array of patterns to exclude.
205
- * @returns The content field from the API response
206
- * @throws APIError if the operation fails.
207
- */
208
- async searchFiles(path, pattern, excludePatterns = []) {
209
- const args = {
210
- path,
211
- pattern
212
- };
213
- if (excludePatterns.length > 0) {
214
- args.exclude_patterns = excludePatterns;
215
- }
216
- const result = await this.callMcpTool('search_files', args, 'Failed to search files');
217
- // Return the raw content field for the caller to parse
218
- return result.data.content;
219
- }
220
- /**
221
- * Writes content to a file.
222
- *
223
- * @param path - Path to the file to write.
224
- * @param content - Content to write to the file.
225
- * @param mode - Optional: Write mode. One of "overwrite", "append", or "create_new". Default is "overwrite".
226
- * @returns The content field from the API response
227
- * @throws APIError if the operation fails.
228
- */
229
- async writeFile(path, content, mode = 'overwrite') {
230
- // Validate mode
231
- const validModes = ['overwrite', 'append', 'create_new'];
232
- if (!validModes.includes(mode)) {
233
- throw new exceptions_1.APIError(`Invalid mode: ${mode}. Must be one of ${validModes.join(', ')}`);
234
- }
235
- const args = {
236
- path,
237
- content,
238
- mode
239
- };
240
- const result = await this.callMcpTool('write_file', args, 'Failed to write file');
241
- // Return the raw content field for the caller to parse
242
- return result.data.content;
243
- }
244
- }
245
- exports.FileSystem = FileSystem;
@@ -1 +0,0 @@
1
- export * from './filesystem';
@@ -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("./filesystem"), exports);
@@ -1,10 +0,0 @@
1
- export { AgentBay } from './agent-bay';
2
- export { Session } from './session';
3
- export { Context, ContextService } from './context';
4
- export * from './exceptions';
5
- export * from './filesystem';
6
- export * from './command';
7
- export * from './oss';
8
- export * from './api';
9
- export * from './application';
10
- export * from './ui';