acontext 0.0.13__py3-none-any.whl → 0.0.14__py3-none-any.whl

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.
acontext/agent/disk.py CHANGED
@@ -261,15 +261,71 @@ class ListTool(BaseTool):
261
261
  if not artifacts_list and not result.directories:
262
262
  return f"No files or directories found in '{normalized_path}'"
263
263
 
264
- output_parts = []
265
- if artifacts_list:
266
- output_parts.append(f"Files: {', '.join(artifacts_list)}")
267
- if result.directories:
268
- output_parts.append(f"Directories: {', '.join(result.directories)}")
269
-
270
- ls_sect = "\n".join(output_parts)
264
+ file_sect = "\n".join(artifacts_list) or "[NO FILE]"
265
+ dir_sect = (
266
+ "\n".join([d.rstrip("/") + "/" for d in result.directories]) or "[NO DIR]"
267
+ )
271
268
  return f"""[Listing in {normalized_path}]
272
- {ls_sect}"""
269
+ Directories:
270
+ {dir_sect}
271
+ Files:
272
+ {file_sect}"""
273
+
274
+
275
+ class DownloadFileTool(BaseTool):
276
+ """Tool for getting a public download URL for a file on the Acontext disk."""
277
+
278
+ @property
279
+ def name(self) -> str:
280
+ return "download_file"
281
+
282
+ @property
283
+ def description(self) -> str:
284
+ return "Get a public URL to download a file. Returns a presigned URL that can be shared or used to access the file."
285
+
286
+ @property
287
+ def arguments(self) -> dict:
288
+ return {
289
+ "file_path": {
290
+ "type": "string",
291
+ "description": "Optional directory path where the file is located, e.g. '/notes/'. Defaults to root '/' if not specified.",
292
+ },
293
+ "filename": {
294
+ "type": "string",
295
+ "description": "Filename to get the download URL for.",
296
+ },
297
+ "expire": {
298
+ "type": "integer",
299
+ "description": "URL expiration time in seconds. Defaults to 3600 (1 hour).",
300
+ },
301
+ }
302
+
303
+ @property
304
+ def required_arguments(self) -> list[str]:
305
+ return ["filename"]
306
+
307
+ def execute(self, ctx: DiskContext, llm_arguments: dict) -> str:
308
+ """Get a public download URL for a file."""
309
+ filename = llm_arguments.get("filename")
310
+ file_path = llm_arguments.get("file_path")
311
+ expire = llm_arguments.get("expire", 3600)
312
+
313
+ if not filename:
314
+ raise ValueError("filename is required")
315
+
316
+ normalized_path = _normalize_path(file_path)
317
+ result = ctx.client.disks.artifacts.get(
318
+ ctx.disk_id,
319
+ file_path=normalized_path,
320
+ filename=filename,
321
+ with_public_url=True,
322
+ expire=expire,
323
+ )
324
+
325
+ if not result.public_url:
326
+ raise RuntimeError("Failed to get public URL: server did not return a URL.")
327
+
328
+ return f"Public download URL for '{normalized_path}{filename}' (expires in {expire}s):\n{result.public_url}"
273
329
 
274
330
 
275
331
  class DiskToolPool(BaseToolPool):
@@ -284,6 +340,7 @@ DISK_TOOLS.add_tool(WriteFileTool())
284
340
  DISK_TOOLS.add_tool(ReadFileTool())
285
341
  DISK_TOOLS.add_tool(ReplaceStringTool())
286
342
  DISK_TOOLS.add_tool(ListTool())
343
+ DISK_TOOLS.add_tool(DownloadFileTool())
287
344
 
288
345
 
289
346
  if __name__ == "__main__":
@@ -323,3 +380,9 @@ if __name__ == "__main__":
323
380
  ctx, "read_file", {"filename": "test.txt", "file_path": "/try/"}
324
381
  )
325
382
  print(r)
383
+ r = DISK_TOOLS.execute_tool(
384
+ ctx,
385
+ "download_file",
386
+ {"filename": "test.txt", "file_path": "/try/", "expire": 300},
387
+ )
388
+ print(r)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: acontext
3
- Version: 0.0.13
3
+ Version: 0.0.14
4
4
  Summary: Python SDK for the Acontext API
5
5
  Keywords: acontext,sdk,client,api
6
6
  Requires-Dist: httpx>=0.28.1
@@ -3,7 +3,7 @@ acontext/_constants.py,sha256=Ikuy_Wz3CPmXjKPLXb4Y580-fe54o1hZ2ZB1Bpw3sFE,363
3
3
  acontext/_utils.py,sha256=GKQH45arKh0sDu64u-5jwrII_ctnU_oChYlgR5lRkfE,1250
4
4
  acontext/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  acontext/agent/base.py,sha256=kN2KzV6fOlvmMSi_0yu2QqwVLtHh09TznAy_SDtC8iM,2998
6
- acontext/agent/disk.py,sha256=tYSvdWKjJ6KIvAk3UzJaQABB4rOL7GAMvEVmI715-hw,10566
6
+ acontext/agent/disk.py,sha256=d9sOggIs4da7niB9TaE0ab82_7l0O5n08eOcQxcaYRs,12623
7
7
  acontext/async_client.py,sha256=mfyR-WVy_LEOXjrkTcXLNaPDC5euaZ9zFI_5e1gapGs,8153
8
8
  acontext/client.py,sha256=jFr5-Q8obdcZBamUNtY3fCklpOJiNiIKLzEApTmbnTg,7920
9
9
  acontext/client_types.py,sha256=uVBWzLbZyXrqkljG49ojdQL_xX6N3n_HGt4Bs_TEE48,987
@@ -28,6 +28,6 @@ acontext/types/session.py,sha256=H_n4vZJ02ZO5flqGZ8R5AYVSScxScf2r7UgsN5LRIa0,996
28
28
  acontext/types/space.py,sha256=uxbPrOHYpsntPHqhMCLQ2KovM7BngHC5Q2j7qexVrN8,2537
29
29
  acontext/types/tool.py,sha256=-mVn-vgk2SENK0Ubt-ZgWFZxKa-ddABqcAgXQ69YY-E,805
30
30
  acontext/uploads.py,sha256=6twnqQOY_eerNuEjeSKsE_3S0IfJUiczXtAy4aXqDl8,1379
31
- acontext-0.0.13.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
32
- acontext-0.0.13.dist-info/METADATA,sha256=xB8jBuzFtOiOMcXpOTvFgb-pvVPx7nwxtdd8cXhaMaE,859
33
- acontext-0.0.13.dist-info/RECORD,,
31
+ acontext-0.0.14.dist-info/WHEEL,sha256=KSLUh82mDPEPk0Bx0ScXlWL64bc8KmzIPNcpQZFV-6E,79
32
+ acontext-0.0.14.dist-info/METADATA,sha256=sm1g1hhGbW15feWubCtcNkjgK5Ja1S_-xr1lIbXvmjU,859
33
+ acontext-0.0.14.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.9.21
2
+ Generator: uv 0.9.22
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any