@acontext/acontext 0.0.20 → 0.1.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.
@@ -59,9 +59,7 @@ class ListSkillsTool extends base_1.AbstractBaseTool {
59
59
  this.arguments = {};
60
60
  this.requiredArguments = [];
61
61
  }
62
- async execute(ctx,
63
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
64
- _llmArguments) {
62
+ async execute(ctx, _llmArguments) {
65
63
  if (ctx.skills.size === 0) {
66
64
  return 'No skills available in the current context.';
67
65
  }
package/dist/client.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { BlocksAPI } from './resources/blocks';
5
5
  import { DisksAPI } from './resources/disks';
6
+ import { SandboxesAPI } from './resources/sandboxes';
6
7
  import { SessionsAPI } from './resources/sessions';
7
8
  import { SpacesAPI } from './resources/spaces';
8
9
  import { ToolsAPI } from './resources/tools';
@@ -28,6 +29,7 @@ export declare class AcontextClient implements RequesterProtocol {
28
29
  tools: ToolsAPI;
29
30
  skills: SkillsAPI;
30
31
  users: UsersAPI;
32
+ sandboxes: SandboxesAPI;
31
33
  constructor(options?: AcontextClientOptions);
32
34
  get baseUrl(): string;
33
35
  /**
package/dist/client.js CHANGED
@@ -40,6 +40,7 @@ exports.AcontextClient = void 0;
40
40
  const errors_1 = require("./errors");
41
41
  const blocks_1 = require("./resources/blocks");
42
42
  const disks_1 = require("./resources/disks");
43
+ const sandboxes_1 = require("./resources/sandboxes");
43
44
  const sessions_1 = require("./resources/sessions");
44
45
  const spaces_1 = require("./resources/spaces");
45
46
  const tools_1 = require("./resources/tools");
@@ -81,6 +82,7 @@ class AcontextClient {
81
82
  this.tools = new tools_1.ToolsAPI(this);
82
83
  this.skills = new skills_1.SkillsAPI(this);
83
84
  this.users = new users_1.UsersAPI(this);
85
+ this.sandboxes = new sandboxes_1.SandboxesAPI(this);
84
86
  }
85
87
  get baseUrl() {
86
88
  return this._baseUrl;
@@ -54,4 +54,16 @@ export declare class DiskArtifactsAPI {
54
54
  query: string;
55
55
  limit?: number;
56
56
  }): Promise<Artifacts>;
57
+ downloadToSandbox(diskId: string, options: {
58
+ filePath: string;
59
+ filename: string;
60
+ sandboxId: string;
61
+ sandboxPath: string;
62
+ }): Promise<boolean>;
63
+ uploadFromSandbox(diskId: string, options: {
64
+ sandboxId: string;
65
+ sandboxPath: string;
66
+ sandboxFilename: string;
67
+ filePath: string;
68
+ }): Promise<Artifact>;
57
69
  }
@@ -122,5 +122,29 @@ class DiskArtifactsAPI {
122
122
  });
123
123
  return types_1.ArtifactsSchema.parse(data);
124
124
  }
125
+ async downloadToSandbox(diskId, options) {
126
+ const payload = {
127
+ file_path: options.filePath,
128
+ filename: options.filename,
129
+ sandbox_id: options.sandboxId,
130
+ sandbox_path: options.sandboxPath,
131
+ };
132
+ const data = await this.requester.request('POST', `/disk/${diskId}/artifact/download_to_sandbox`, {
133
+ jsonData: payload,
134
+ });
135
+ return Boolean(data?.success);
136
+ }
137
+ async uploadFromSandbox(diskId, options) {
138
+ const payload = {
139
+ sandbox_id: options.sandboxId,
140
+ sandbox_path: options.sandboxPath,
141
+ sandbox_filename: options.sandboxFilename,
142
+ file_path: options.filePath,
143
+ };
144
+ const data = await this.requester.request('POST', `/disk/${diskId}/artifact/upload_from_sandbox`, {
145
+ jsonData: payload,
146
+ });
147
+ return types_1.ArtifactSchema.parse(data);
148
+ }
125
149
  }
126
150
  exports.DiskArtifactsAPI = DiskArtifactsAPI;
@@ -7,4 +7,5 @@ export * from './disks';
7
7
  export * from './blocks';
8
8
  export * from './tools';
9
9
  export * from './skills';
10
+ export * from './sandboxes';
10
11
  export * from './users';
@@ -23,4 +23,5 @@ __exportStar(require("./disks"), exports);
23
23
  __exportStar(require("./blocks"), exports);
24
24
  __exportStar(require("./tools"), exports);
25
25
  __exportStar(require("./skills"), exports);
26
+ __exportStar(require("./sandboxes"), exports);
26
27
  __exportStar(require("./users"), exports);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Sandboxes endpoints.
3
+ */
4
+ import { RequesterProtocol } from '../client-types';
5
+ import { FlagResponse, SandboxCommandOutput, SandboxRuntimeInfo } from '../types';
6
+ export declare class SandboxesAPI {
7
+ private requester;
8
+ constructor(requester: RequesterProtocol);
9
+ /**
10
+ * Create and start a new sandbox.
11
+ *
12
+ * @returns SandboxRuntimeInfo containing the sandbox ID, status, and timestamps
13
+ */
14
+ create(): Promise<SandboxRuntimeInfo>;
15
+ /**
16
+ * Execute a shell command in the sandbox.
17
+ *
18
+ * @param options - Command execution options
19
+ * @param options.sandboxId - The UUID of the sandbox
20
+ * @param options.command - The shell command to execute
21
+ * @returns SandboxCommandOutput containing stdout, stderr, and exit code
22
+ */
23
+ execCommand(options: {
24
+ sandboxId: string;
25
+ command: string;
26
+ }): Promise<SandboxCommandOutput>;
27
+ /**
28
+ * Kill a running sandbox.
29
+ *
30
+ * @param sandboxId - The UUID of the sandbox to kill
31
+ * @returns FlagResponse with status and error message
32
+ */
33
+ kill(sandboxId: string): Promise<FlagResponse>;
34
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Sandboxes endpoints.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SandboxesAPI = void 0;
7
+ const types_1 = require("../types");
8
+ class SandboxesAPI {
9
+ constructor(requester) {
10
+ this.requester = requester;
11
+ }
12
+ /**
13
+ * Create and start a new sandbox.
14
+ *
15
+ * @returns SandboxRuntimeInfo containing the sandbox ID, status, and timestamps
16
+ */
17
+ async create() {
18
+ const data = await this.requester.request('POST', '/sandbox');
19
+ return types_1.SandboxRuntimeInfoSchema.parse(data);
20
+ }
21
+ /**
22
+ * Execute a shell command in the sandbox.
23
+ *
24
+ * @param options - Command execution options
25
+ * @param options.sandboxId - The UUID of the sandbox
26
+ * @param options.command - The shell command to execute
27
+ * @returns SandboxCommandOutput containing stdout, stderr, and exit code
28
+ */
29
+ async execCommand(options) {
30
+ const data = await this.requester.request('POST', `/sandbox/${options.sandboxId}/exec`, {
31
+ jsonData: { command: options.command },
32
+ });
33
+ return types_1.SandboxCommandOutputSchema.parse(data);
34
+ }
35
+ /**
36
+ * Kill a running sandbox.
37
+ *
38
+ * @param sandboxId - The UUID of the sandbox to kill
39
+ * @returns FlagResponse with status and error message
40
+ */
41
+ async kill(sandboxId) {
42
+ const data = await this.requester.request('DELETE', `/sandbox/${sandboxId}`);
43
+ return types_1.FlagResponseSchema.parse(data);
44
+ }
45
+ }
46
+ exports.SandboxesAPI = SandboxesAPI;
@@ -36,6 +36,17 @@ export declare class SessionsAPI {
36
36
  cursor?: string | null;
37
37
  timeDesc?: boolean | null;
38
38
  }): Promise<GetTasksOutput>;
39
+ /**
40
+ * Get a summary of all tasks in a session as a formatted string.
41
+ *
42
+ * @param sessionId - The UUID of the session.
43
+ * @param options - Options for retrieving the summary.
44
+ * @param options.limit - Maximum number of tasks to include in the summary.
45
+ * @returns A formatted string containing the session summary with all task information.
46
+ */
47
+ getSessionSummary(sessionId: string, options?: {
48
+ limit?: number | null;
49
+ }): Promise<string>;
39
50
  storeMessage(sessionId: string, blob: MessageBlob, options?: {
40
51
  format?: 'acontext' | 'openai' | 'anthropic' | 'gemini';
41
52
  fileField?: string | null;
@@ -54,6 +65,7 @@ export declare class SessionsAPI {
54
65
  * @param options.editStrategies - Optional list of edit strategies to apply before format conversion.
55
66
  * Examples:
56
67
  * - Remove tool results: [{ type: 'remove_tool_result', params: { keep_recent_n_tool_results: 3 } }]
68
+ * - Middle out: [{ type: 'middle_out', params: { token_reduce_to: 5000 } }]
57
69
  * - Token limit: [{ type: 'token_limit', params: { limit_tokens: 20000 } }]
58
70
  * @param options.pinEditingStrategiesAtMessage - Message ID to pin editing strategies at.
59
71
  * When provided, strategies are only applied to messages up to and including this message ID,
@@ -79,6 +79,47 @@ class SessionsAPI {
79
79
  });
80
80
  return types_1.GetTasksOutputSchema.parse(data);
81
81
  }
82
+ /**
83
+ * Get a summary of all tasks in a session as a formatted string.
84
+ *
85
+ * @param sessionId - The UUID of the session.
86
+ * @param options - Options for retrieving the summary.
87
+ * @param options.limit - Maximum number of tasks to include in the summary.
88
+ * @returns A formatted string containing the session summary with all task information.
89
+ */
90
+ async getSessionSummary(sessionId, options) {
91
+ const tasksOutput = await this.getTasks(sessionId, {
92
+ limit: options?.limit,
93
+ timeDesc: false,
94
+ });
95
+ const tasks = tasksOutput.items;
96
+ if (tasks.length === 0) {
97
+ return '';
98
+ }
99
+ const parts = [];
100
+ for (const task of tasks) {
101
+ const taskLines = [
102
+ `<task id="${task.order}" description="${task.data.task_description}">`
103
+ ];
104
+ if (task.data.progresses && task.data.progresses.length > 0) {
105
+ taskLines.push('<progress>');
106
+ task.data.progresses.forEach((p, i) => {
107
+ taskLines.push(`${i + 1}. ${p}`);
108
+ });
109
+ taskLines.push('</progress>');
110
+ }
111
+ if (task.data.user_preferences && task.data.user_preferences.length > 0) {
112
+ taskLines.push('<user_preference>');
113
+ task.data.user_preferences.forEach((pref, i) => {
114
+ taskLines.push(`${i + 1}. ${pref}`);
115
+ });
116
+ taskLines.push('</user_preference>');
117
+ }
118
+ taskLines.push('</task>');
119
+ parts.push(taskLines.join('\n'));
120
+ }
121
+ return parts.join('\n');
122
+ }
82
123
  async storeMessage(sessionId, blob, options) {
83
124
  const format = options?.format ?? 'openai';
84
125
  if (!['acontext', 'openai', 'anthropic', 'gemini'].includes(format)) {
@@ -137,6 +178,7 @@ class SessionsAPI {
137
178
  * @param options.editStrategies - Optional list of edit strategies to apply before format conversion.
138
179
  * Examples:
139
180
  * - Remove tool results: [{ type: 'remove_tool_result', params: { keep_recent_n_tool_results: 3 } }]
181
+ * - Middle out: [{ type: 'middle_out', params: { token_reduce_to: 5000 } }]
140
182
  * - Token limit: [{ type: 'token_limit', params: { limit_tokens: 20000 } }]
141
183
  * @param options.pinEditingStrategiesAtMessage - Message ID to pin editing strategies at.
142
184
  * When provided, strategies are only applied to messages up to and including this message ID,
@@ -23,7 +23,7 @@ export declare class SkillsAPI {
23
23
  * @returns ListSkillsOutput containing skills with name and description for the current page,
24
24
  * along with pagination information (next_cursor and has_more)
25
25
  */
26
- list_catalog(options?: {
26
+ listCatalog(options?: {
27
27
  user?: string | null;
28
28
  limit?: number | null;
29
29
  cursor?: string | null;
@@ -40,7 +40,7 @@ class SkillsAPI {
40
40
  * @returns ListSkillsOutput containing skills with name and description for the current page,
41
41
  * along with pagination information (next_cursor and has_more)
42
42
  */
43
- async list_catalog(options) {
43
+ async listCatalog(options) {
44
44
  // Use 100 as default for catalog listing (only name and description, lightweight)
45
45
  const effectiveLimit = options?.limit ?? 100;
46
46
  const params = (0, utils_1.buildParams)({
@@ -8,4 +8,5 @@ export * from './disk';
8
8
  export * from './block';
9
9
  export * from './tool';
10
10
  export * from './skill';
11
+ export * from './sandbox';
11
12
  export * from './user';
@@ -24,4 +24,5 @@ __exportStar(require("./disk"), exports);
24
24
  __exportStar(require("./block"), exports);
25
25
  __exportStar(require("./tool"), exports);
26
26
  __exportStar(require("./skill"), exports);
27
+ __exportStar(require("./sandbox"), exports);
27
28
  __exportStar(require("./user"), exports);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Type definitions for sandbox resources.
3
+ */
4
+ import { z } from 'zod';
5
+ export declare const SandboxRuntimeInfoSchema: z.ZodObject<{
6
+ sandbox_id: z.ZodString;
7
+ sandbox_status: z.ZodString;
8
+ sandbox_created_at: z.ZodString;
9
+ sandbox_expires_at: z.ZodString;
10
+ }, z.core.$strip>;
11
+ export type SandboxRuntimeInfo = z.infer<typeof SandboxRuntimeInfoSchema>;
12
+ export declare const SandboxCommandOutputSchema: z.ZodObject<{
13
+ stdout: z.ZodString;
14
+ stderr: z.ZodString;
15
+ exit_code: z.ZodNumber;
16
+ }, z.core.$strip>;
17
+ export type SandboxCommandOutput = z.infer<typeof SandboxCommandOutputSchema>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * Type definitions for sandbox resources.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SandboxCommandOutputSchema = exports.SandboxRuntimeInfoSchema = void 0;
7
+ const zod_1 = require("zod");
8
+ exports.SandboxRuntimeInfoSchema = zod_1.z.object({
9
+ sandbox_id: zod_1.z.string(),
10
+ sandbox_status: zod_1.z.string(),
11
+ sandbox_created_at: zod_1.z.string(),
12
+ sandbox_expires_at: zod_1.z.string(),
13
+ });
14
+ exports.SandboxCommandOutputSchema = zod_1.z.object({
15
+ stdout: zod_1.z.string(),
16
+ stderr: zod_1.z.string(),
17
+ exit_code: zod_1.z.number(),
18
+ });
@@ -235,6 +235,25 @@ export declare const TokenLimitStrategySchema: z.ZodObject<{
235
235
  }, z.core.$strip>;
236
236
  }, z.core.$strip>;
237
237
  export type TokenLimitStrategy = z.infer<typeof TokenLimitStrategySchema>;
238
+ /**
239
+ * Parameters for the middle_out edit strategy.
240
+ */
241
+ export declare const MiddleOutParamsSchema: z.ZodObject<{
242
+ token_reduce_to: z.ZodNumber;
243
+ }, z.core.$strip>;
244
+ export type MiddleOutParams = z.infer<typeof MiddleOutParamsSchema>;
245
+ /**
246
+ * Edit strategy to reduce prompt size by removing middle messages.
247
+ *
248
+ * Example: { type: 'middle_out', params: { token_reduce_to: 5000 } }
249
+ */
250
+ export declare const MiddleOutStrategySchema: z.ZodObject<{
251
+ type: z.ZodLiteral<"middle_out">;
252
+ params: z.ZodObject<{
253
+ token_reduce_to: z.ZodNumber;
254
+ }, z.core.$strip>;
255
+ }, z.core.$strip>;
256
+ export type MiddleOutStrategy = z.infer<typeof MiddleOutStrategySchema>;
238
257
  /**
239
258
  * Union schema for all edit strategies.
240
259
  * When adding new strategies, extend this union: z.union([RemoveToolResultStrategySchema, OtherStrategySchema, ...])
@@ -257,5 +276,10 @@ export declare const EditStrategySchema: z.ZodUnion<readonly [z.ZodObject<{
257
276
  params: z.ZodObject<{
258
277
  limit_tokens: z.ZodNumber;
259
278
  }, z.core.$strip>;
279
+ }, z.core.$strip>, z.ZodObject<{
280
+ type: z.ZodLiteral<"middle_out">;
281
+ params: z.ZodObject<{
282
+ token_reduce_to: z.ZodNumber;
283
+ }, z.core.$strip>;
260
284
  }, z.core.$strip>]>;
261
285
  export type EditStrategy = z.infer<typeof EditStrategySchema>;
@@ -3,7 +3,7 @@
3
3
  * Type definitions for session, message, and task resources.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EditStrategySchema = exports.TokenLimitStrategySchema = exports.TokenLimitParamsSchema = exports.RemoveToolResultStrategySchema = exports.RemoveToolCallParamsStrategySchema = exports.RemoveToolCallParamsParamsSchema = exports.RemoveToolResultParamsSchema = exports.MessageObservingStatusSchema = exports.TokenCountsSchema = exports.LearningStatusSchema = exports.GetTasksOutputSchema = exports.GetMessagesOutputSchema = exports.PublicURLSchema = exports.ListSessionsOutputSchema = exports.TaskSchema = exports.TaskDataSchema = exports.SessionSchema = exports.MessageSchema = exports.PartSchema = exports.AssetSchema = void 0;
6
+ exports.EditStrategySchema = exports.MiddleOutStrategySchema = exports.MiddleOutParamsSchema = exports.TokenLimitStrategySchema = exports.TokenLimitParamsSchema = exports.RemoveToolResultStrategySchema = exports.RemoveToolCallParamsStrategySchema = exports.RemoveToolCallParamsParamsSchema = exports.RemoveToolResultParamsSchema = exports.MessageObservingStatusSchema = exports.TokenCountsSchema = exports.LearningStatusSchema = exports.GetTasksOutputSchema = exports.GetMessagesOutputSchema = exports.PublicURLSchema = exports.ListSessionsOutputSchema = exports.TaskSchema = exports.TaskDataSchema = exports.SessionSchema = exports.MessageSchema = exports.PartSchema = exports.AssetSchema = void 0;
7
7
  const zod_1 = require("zod");
8
8
  exports.AssetSchema = zod_1.z.object({
9
9
  bucket: zod_1.z.string(),
@@ -190,6 +190,21 @@ exports.TokenLimitStrategySchema = zod_1.z.object({
190
190
  type: zod_1.z.literal('token_limit'),
191
191
  params: exports.TokenLimitParamsSchema,
192
192
  });
193
+ /**
194
+ * Parameters for the middle_out edit strategy.
195
+ */
196
+ exports.MiddleOutParamsSchema = zod_1.z.object({
197
+ token_reduce_to: zod_1.z.number(),
198
+ });
199
+ /**
200
+ * Edit strategy to reduce prompt size by removing middle messages.
201
+ *
202
+ * Example: { type: 'middle_out', params: { token_reduce_to: 5000 } }
203
+ */
204
+ exports.MiddleOutStrategySchema = zod_1.z.object({
205
+ type: zod_1.z.literal('middle_out'),
206
+ params: exports.MiddleOutParamsSchema,
207
+ });
193
208
  /**
194
209
  * Union schema for all edit strategies.
195
210
  * When adding new strategies, extend this union: z.union([RemoveToolResultStrategySchema, OtherStrategySchema, ...])
@@ -198,4 +213,5 @@ exports.EditStrategySchema = zod_1.z.union([
198
213
  exports.RemoveToolResultStrategySchema,
199
214
  exports.RemoveToolCallParamsStrategySchema,
200
215
  exports.TokenLimitStrategySchema,
216
+ exports.MiddleOutStrategySchema,
201
217
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acontext/acontext",
3
- "version": "0.0.20",
3
+ "version": "0.1.0",
4
4
  "description": "TypeScript SDK for the Acontext API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,6 +9,7 @@
9
9
  "dev": "tsc --watch",
10
10
  "test": "jest",
11
11
  "lint": "eslint src",
12
+ "e2e": "tsx examples/basic-usage.ts",
12
13
  "prepublishOnly": "npm run build"
13
14
  },
14
15
  "keywords": [
@@ -35,6 +36,7 @@
35
36
  "eslint": "^9.39.1",
36
37
  "jest": "^30.2.0",
37
38
  "ts-jest": "^29.4.5",
39
+ "tsx": "^4.19.0",
38
40
  "typescript": "^5.9.3"
39
41
  },
40
42
  "peerDependencies": {