@acontext/acontext 0.1.11 → 0.1.13
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 +1 -1
- package/dist/agent/sandbox.js +6 -4
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/resources/learning-spaces.d.ts +16 -0
- package/dist/resources/learning-spaces.js +31 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,4 +10,4 @@ npm install @acontext/acontext
|
|
|
10
10
|
|
|
11
11
|
# 🔍 Document
|
|
12
12
|
|
|
13
|
-
To understand more about this SDK, please view [our docs](https://docs.acontext.
|
|
13
|
+
To understand more about this SDK, please view [our docs](https://docs.acontext.app/) and [api references](https://docs.acontext.app/api-reference/introduction)
|
package/dist/agent/sandbox.js
CHANGED
|
@@ -117,7 +117,8 @@ class BashTool extends base_1.AbstractBaseTool {
|
|
|
117
117
|
}
|
|
118
118
|
async execute(ctx, llmArguments) {
|
|
119
119
|
const command = llmArguments.command;
|
|
120
|
-
const
|
|
120
|
+
const timeoutSec = llmArguments.timeout ?? this._timeout;
|
|
121
|
+
const timeout = timeoutSec != null ? timeoutSec * 1000 : undefined;
|
|
121
122
|
if (!command) {
|
|
122
123
|
throw new Error('command is required');
|
|
123
124
|
}
|
|
@@ -177,6 +178,7 @@ class TextEditorTool extends base_1.AbstractBaseTool {
|
|
|
177
178
|
async execute(ctx, llmArguments) {
|
|
178
179
|
const command = llmArguments.command;
|
|
179
180
|
const path = llmArguments.path;
|
|
181
|
+
const timeoutMs = this._timeout != null ? this._timeout * 1000 : undefined;
|
|
180
182
|
if (!command) {
|
|
181
183
|
throw new Error('command is required');
|
|
182
184
|
}
|
|
@@ -185,7 +187,7 @@ class TextEditorTool extends base_1.AbstractBaseTool {
|
|
|
185
187
|
}
|
|
186
188
|
if (command === 'view') {
|
|
187
189
|
const viewRange = llmArguments.view_range;
|
|
188
|
-
const result = await (0, text_editor_1.viewFile)(ctx, path, viewRange,
|
|
190
|
+
const result = await (0, text_editor_1.viewFile)(ctx, path, viewRange, timeoutMs);
|
|
189
191
|
return JSON.stringify(result);
|
|
190
192
|
}
|
|
191
193
|
else if (command === 'create') {
|
|
@@ -193,7 +195,7 @@ class TextEditorTool extends base_1.AbstractBaseTool {
|
|
|
193
195
|
if (fileText === null || fileText === undefined) {
|
|
194
196
|
throw new Error('file_text is required for create command');
|
|
195
197
|
}
|
|
196
|
-
const result = await (0, text_editor_1.createFile)(ctx, path, fileText,
|
|
198
|
+
const result = await (0, text_editor_1.createFile)(ctx, path, fileText, timeoutMs);
|
|
197
199
|
return JSON.stringify(result);
|
|
198
200
|
}
|
|
199
201
|
else if (command === 'str_replace') {
|
|
@@ -205,7 +207,7 @@ class TextEditorTool extends base_1.AbstractBaseTool {
|
|
|
205
207
|
if (newStr === null || newStr === undefined) {
|
|
206
208
|
throw new Error('new_str is required for str_replace command');
|
|
207
209
|
}
|
|
208
|
-
const result = await (0, text_editor_1.strReplace)(ctx, path, oldStr, newStr,
|
|
210
|
+
const result = await (0, text_editor_1.strReplace)(ctx, path, oldStr, newStr, timeoutMs);
|
|
209
211
|
return JSON.stringify(result);
|
|
210
212
|
}
|
|
211
213
|
else {
|
package/dist/errors.d.ts
CHANGED
|
@@ -30,3 +30,9 @@ export declare class APIError extends AcontextError {
|
|
|
30
30
|
export declare class TransportError extends AcontextError {
|
|
31
31
|
constructor(message: string);
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Raised when a polling operation exceeds the configured timeout.
|
|
35
|
+
*/
|
|
36
|
+
export declare class TimeoutError extends AcontextError {
|
|
37
|
+
constructor(message?: string);
|
|
38
|
+
}
|
package/dist/errors.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Custom exceptions raised by the acontext TypeScript client.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TransportError = exports.APIError = exports.AcontextError = void 0;
|
|
6
|
+
exports.TimeoutError = exports.TransportError = exports.APIError = exports.AcontextError = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Base exception for all errors raised by `acontext`.
|
|
9
9
|
*/
|
|
@@ -43,3 +43,14 @@ class TransportError extends AcontextError {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
exports.TransportError = TransportError;
|
|
46
|
+
/**
|
|
47
|
+
* Raised when a polling operation exceeds the configured timeout.
|
|
48
|
+
*/
|
|
49
|
+
class TimeoutError extends AcontextError {
|
|
50
|
+
constructor(message = 'operation timed out') {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = 'TimeoutError';
|
|
53
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.TimeoutError = TimeoutError;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { AcontextClient } from './client';
|
|
|
5
5
|
export type { AcontextClientOptions } from './client';
|
|
6
6
|
export { FileUpload } from './uploads';
|
|
7
7
|
export { MessagePart, AcontextMessage, buildAcontextMessage } from './messages';
|
|
8
|
-
export { APIError, TransportError, AcontextError } from './errors';
|
|
8
|
+
export { APIError, TransportError, AcontextError, TimeoutError } from './errors';
|
|
9
9
|
export * from './types';
|
|
10
10
|
export * from './resources';
|
|
11
11
|
export * from './agent';
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.AcontextError = exports.TransportError = exports.APIError = exports.buildAcontextMessage = exports.AcontextMessage = exports.MessagePart = exports.FileUpload = exports.AcontextClient = void 0;
|
|
20
|
+
exports.TimeoutError = exports.AcontextError = exports.TransportError = exports.APIError = exports.buildAcontextMessage = exports.AcontextMessage = exports.MessagePart = exports.FileUpload = exports.AcontextClient = void 0;
|
|
21
21
|
var client_1 = require("./client");
|
|
22
22
|
Object.defineProperty(exports, "AcontextClient", { enumerable: true, get: function () { return client_1.AcontextClient; } });
|
|
23
23
|
var uploads_1 = require("./uploads");
|
|
@@ -30,6 +30,7 @@ var errors_1 = require("./errors");
|
|
|
30
30
|
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_1.APIError; } });
|
|
31
31
|
Object.defineProperty(exports, "TransportError", { enumerable: true, get: function () { return errors_1.TransportError; } });
|
|
32
32
|
Object.defineProperty(exports, "AcontextError", { enumerable: true, get: function () { return errors_1.AcontextError; } });
|
|
33
|
+
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
|
|
33
34
|
__exportStar(require("./types"), exports);
|
|
34
35
|
__exportStar(require("./resources"), exports);
|
|
35
36
|
__exportStar(require("./agent"), exports);
|
|
@@ -44,6 +44,22 @@ export declare class LearningSpacesAPI {
|
|
|
44
44
|
spaceId: string;
|
|
45
45
|
sessionId: string;
|
|
46
46
|
}): Promise<LearningSpaceSession>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a single learning session record by session ID.
|
|
49
|
+
*/
|
|
50
|
+
getSession(options: {
|
|
51
|
+
spaceId: string;
|
|
52
|
+
sessionId: string;
|
|
53
|
+
}): Promise<LearningSpaceSession>;
|
|
54
|
+
/**
|
|
55
|
+
* Poll until a learning session reaches a terminal status.
|
|
56
|
+
*/
|
|
57
|
+
waitForLearning(options: {
|
|
58
|
+
spaceId: string;
|
|
59
|
+
sessionId: string;
|
|
60
|
+
timeout?: number;
|
|
61
|
+
pollInterval?: number;
|
|
62
|
+
}): Promise<LearningSpaceSession>;
|
|
47
63
|
/**
|
|
48
64
|
* List all learning session records for a space.
|
|
49
65
|
*/
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.LearningSpacesAPI = void 0;
|
|
7
|
+
const errors_1 = require("../errors");
|
|
7
8
|
const utils_1 = require("../utils");
|
|
8
9
|
const types_1 = require("../types");
|
|
9
10
|
class LearningSpacesAPI {
|
|
@@ -74,6 +75,36 @@ class LearningSpacesAPI {
|
|
|
74
75
|
const data = await this.requester.request('POST', `/learning_spaces/${options.spaceId}/learn`, { jsonData: { session_id: options.sessionId } });
|
|
75
76
|
return types_1.LearningSpaceSessionSchema.parse(data);
|
|
76
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Get a single learning session record by session ID.
|
|
80
|
+
*/
|
|
81
|
+
async getSession(options) {
|
|
82
|
+
const data = await this.requester.request('GET', `/learning_spaces/${options.spaceId}/sessions/${options.sessionId}`);
|
|
83
|
+
return types_1.LearningSpaceSessionSchema.parse(data);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Poll until a learning session reaches a terminal status.
|
|
87
|
+
*/
|
|
88
|
+
async waitForLearning(options) {
|
|
89
|
+
const timeout = options.timeout ?? 120;
|
|
90
|
+
const pollInterval = options.pollInterval ?? 1;
|
|
91
|
+
const terminal = new Set(['completed', 'failed']);
|
|
92
|
+
const deadline = Date.now() + timeout * 1000;
|
|
93
|
+
while (true) {
|
|
94
|
+
const session = await this.getSession({
|
|
95
|
+
spaceId: options.spaceId,
|
|
96
|
+
sessionId: options.sessionId,
|
|
97
|
+
});
|
|
98
|
+
if (terminal.has(session.status)) {
|
|
99
|
+
return session;
|
|
100
|
+
}
|
|
101
|
+
if (Date.now() >= deadline) {
|
|
102
|
+
throw new errors_1.TimeoutError(`learning session ${options.sessionId} did not complete within ${timeout}s ` +
|
|
103
|
+
`(last status: ${session.status})`);
|
|
104
|
+
}
|
|
105
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval * 1000));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
77
108
|
/**
|
|
78
109
|
* List all learning session records for a space.
|
|
79
110
|
*/
|