@acontext/acontext 0.0.15 → 0.0.16

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.
@@ -87,6 +87,26 @@ export declare class ListTool extends AbstractBaseTool {
87
87
  readonly requiredArguments: string[];
88
88
  execute(ctx: DiskContext, llmArguments: Record<string, unknown>): Promise<string>;
89
89
  }
90
+ export declare class DownloadFileTool extends AbstractBaseTool {
91
+ readonly name = "download_file";
92
+ readonly description = "Get a public URL to download a file. Returns a presigned URL that can be shared or used to access the file.";
93
+ readonly arguments: {
94
+ file_path: {
95
+ type: string;
96
+ description: string;
97
+ };
98
+ filename: {
99
+ type: string;
100
+ description: string;
101
+ };
102
+ expire: {
103
+ type: string;
104
+ description: string;
105
+ };
106
+ };
107
+ readonly requiredArguments: string[];
108
+ execute(ctx: DiskContext, llmArguments: Record<string, unknown>): Promise<string>;
109
+ }
90
110
  export declare class DiskToolPool extends BaseToolPool {
91
111
  formatContext(client: AcontextClient, diskId: string): DiskContext;
92
112
  }
@@ -3,7 +3,7 @@
3
3
  * Disk tools for agent operations.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DISK_TOOLS = exports.DiskToolPool = exports.ListTool = exports.ReplaceStringTool = exports.ReadFileTool = exports.WriteFileTool = void 0;
6
+ exports.DISK_TOOLS = exports.DiskToolPool = exports.DownloadFileTool = exports.ListTool = exports.ReplaceStringTool = exports.ReadFileTool = exports.WriteFileTool = void 0;
7
7
  const uploads_1 = require("../uploads");
8
8
  const base_1 = require("./base");
9
9
  function normalizePath(path) {
@@ -212,21 +212,56 @@ class ListTool extends base_1.AbstractBaseTool {
212
212
  path: normalizedPath,
213
213
  });
214
214
  const artifactsList = result.artifacts.map((artifact) => artifact.filename);
215
- if (artifactsList.length === 0 && result.directories.length === 0) {
216
- return `No files or directories found in '${normalizedPath}'`;
217
- }
218
- const outputParts = [];
219
- if (artifactsList.length > 0) {
220
- outputParts.push(`Files: ${artifactsList.join(', ')}`);
215
+ const fileSect = artifactsList.length > 0 ? artifactsList.join('\n') : '[NO FILE]';
216
+ const dirSect = result.directories.length > 0
217
+ ? result.directories.map((d) => d.replace(/\/$/, '') + '/').join('\n')
218
+ : '[NO DIR]';
219
+ return `[Listing in ${normalizedPath}]\nDirectories:\n${dirSect}\nFiles:\n${fileSect}`;
220
+ }
221
+ }
222
+ exports.ListTool = ListTool;
223
+ class DownloadFileTool extends base_1.AbstractBaseTool {
224
+ constructor() {
225
+ super(...arguments);
226
+ this.name = 'download_file';
227
+ this.description = 'Get a public URL to download a file. Returns a presigned URL that can be shared or used to access the file.';
228
+ this.arguments = {
229
+ file_path: {
230
+ type: 'string',
231
+ description: "Optional directory path where the file is located, e.g. '/notes/'. Defaults to root '/' if not specified.",
232
+ },
233
+ filename: {
234
+ type: 'string',
235
+ description: 'Filename to get the download URL for.',
236
+ },
237
+ expire: {
238
+ type: 'integer',
239
+ description: 'URL expiration time in seconds. Defaults to 3600 (1 hour).',
240
+ },
241
+ };
242
+ this.requiredArguments = ['filename'];
243
+ }
244
+ async execute(ctx, llmArguments) {
245
+ const filename = llmArguments.filename;
246
+ const filePath = llmArguments.file_path || null;
247
+ const expire = llmArguments.expire || 3600;
248
+ if (!filename) {
249
+ throw new Error('filename is required');
221
250
  }
222
- if (result.directories.length > 0) {
223
- outputParts.push(`Directories: ${result.directories.join(', ')}`);
251
+ const normalizedPath = normalizePath(filePath);
252
+ const result = await ctx.client.disks.artifacts.get(ctx.diskId, {
253
+ filePath: normalizedPath,
254
+ filename,
255
+ withPublicUrl: true,
256
+ expire,
257
+ });
258
+ if (!result.public_url) {
259
+ throw new Error('Failed to get public URL: server did not return a URL.');
224
260
  }
225
- const lsSect = outputParts.join('\n');
226
- return `[Listing in ${normalizedPath}]\n${lsSect}`;
261
+ return `Public download URL for '${normalizedPath}${filename}' (expires in ${expire}s):\n${result.public_url}`;
227
262
  }
228
263
  }
229
- exports.ListTool = ListTool;
264
+ exports.DownloadFileTool = DownloadFileTool;
230
265
  class DiskToolPool extends base_1.BaseToolPool {
231
266
  formatContext(client, diskId) {
232
267
  return {
@@ -241,3 +276,4 @@ exports.DISK_TOOLS.addTool(new WriteFileTool());
241
276
  exports.DISK_TOOLS.addTool(new ReadFileTool());
242
277
  exports.DISK_TOOLS.addTool(new ReplaceStringTool());
243
278
  exports.DISK_TOOLS.addTool(new ListTool());
279
+ exports.DISK_TOOLS.addTool(new DownloadFileTool());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acontext/acontext",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "TypeScript SDK for the Acontext API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",