acontext 0.0.16__py3-none-any.whl → 0.0.17__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
@@ -328,6 +328,110 @@ class DownloadFileTool(BaseTool):
328
328
  return f"Public download URL for '{normalized_path}{filename}' (expires in {expire}s):\n{result.public_url}"
329
329
 
330
330
 
331
+ class GrepArtifactsTool(BaseTool):
332
+ """Tool for searching artifact content using regex patterns."""
333
+
334
+ @property
335
+ def name(self) -> str:
336
+ return "grep_artifacts"
337
+
338
+ @property
339
+ def description(self) -> str:
340
+ return "Search for text patterns within file contents using regex. Only searches text-based files (code, markdown, json, csv, etc.). Use this to find specific code patterns, TODO comments, function definitions, or any text content."
341
+
342
+ @property
343
+ def arguments(self) -> dict:
344
+ return {
345
+ "query": {
346
+ "type": "string",
347
+ "description": "Regex pattern to search for (e.g., 'TODO.*', 'function.*calculate', 'import.*pandas')",
348
+ },
349
+ "limit": {
350
+ "type": "integer",
351
+ "description": "Maximum number of results to return (default 100)",
352
+ },
353
+ }
354
+
355
+ @property
356
+ def required_arguments(self) -> list[str]:
357
+ return ["query"]
358
+
359
+ def execute(self, ctx: DiskContext, llm_arguments: dict) -> str:
360
+ """Search artifact content using regex pattern."""
361
+ query = llm_arguments.get("query")
362
+ limit = llm_arguments.get("limit", 100)
363
+
364
+ if not query:
365
+ raise ValueError("query is required")
366
+
367
+ results = ctx.client.disks.artifacts.grep_artifacts(
368
+ ctx.disk_id,
369
+ query=query,
370
+ limit=limit,
371
+ )
372
+
373
+ if not results:
374
+ return f"No matches found for pattern '{query}'"
375
+
376
+ matches = []
377
+ for artifact in results:
378
+ matches.append(f"{artifact.path}{artifact.filename}")
379
+
380
+ return f"Found {len(matches)} file(s) matching '{query}':\n" + "\n".join(matches)
381
+
382
+
383
+ class GlobArtifactsTool(BaseTool):
384
+ """Tool for finding files by path pattern using glob syntax."""
385
+
386
+ @property
387
+ def name(self) -> str:
388
+ return "glob_artifacts"
389
+
390
+ @property
391
+ def description(self) -> str:
392
+ return "Find files by path pattern using glob syntax. Use * for any characters, ? for single character, ** for recursive directories. Perfect for finding files by extension or location."
393
+
394
+ @property
395
+ def arguments(self) -> dict:
396
+ return {
397
+ "query": {
398
+ "type": "string",
399
+ "description": "Glob pattern (e.g., '**/*.py' for all Python files, '*.txt' for text files in root, '/docs/**/*.md' for markdown in docs)",
400
+ },
401
+ "limit": {
402
+ "type": "integer",
403
+ "description": "Maximum number of results to return (default 100)",
404
+ },
405
+ }
406
+
407
+ @property
408
+ def required_arguments(self) -> list[str]:
409
+ return ["query"]
410
+
411
+ def execute(self, ctx: DiskContext, llm_arguments: dict) -> str:
412
+ """Search artifact paths using glob pattern."""
413
+ query = llm_arguments.get("query")
414
+ limit = llm_arguments.get("limit", 100)
415
+
416
+ if not query:
417
+ raise ValueError("query is required")
418
+
419
+ results = ctx.client.disks.artifacts.glob_artifacts(
420
+ ctx.disk_id,
421
+ query=query,
422
+ limit=limit,
423
+ )
424
+
425
+ if not results:
426
+ return f"No files found matching pattern '{query}'"
427
+
428
+ matches = []
429
+ for artifact in results:
430
+ matches.append(f"{artifact.path}{artifact.filename}")
431
+
432
+ return f"Found {len(matches)} file(s) matching '{query}':\n" + "\n".join(matches)
433
+
434
+
331
435
  class DiskToolPool(BaseToolPool):
332
436
  """Tool pool for disk operations on Acontext disks."""
333
437
 
@@ -340,6 +444,8 @@ DISK_TOOLS.add_tool(WriteFileTool())
340
444
  DISK_TOOLS.add_tool(ReadFileTool())
341
445
  DISK_TOOLS.add_tool(ReplaceStringTool())
342
446
  DISK_TOOLS.add_tool(ListTool())
447
+ DISK_TOOLS.add_tool(GrepArtifactsTool())
448
+ DISK_TOOLS.add_tool(GlobArtifactsTool())
343
449
  DISK_TOOLS.add_tool(DownloadFileTool())
344
450
 
345
451
 
@@ -4,13 +4,50 @@ User management endpoints (async).
4
4
 
5
5
  from urllib.parse import quote
6
6
 
7
+ from .._utils import build_params
7
8
  from ..client_types import AsyncRequesterProtocol
9
+ from ..types.user import GetUserResourcesOutput, ListUsersOutput
8
10
 
9
11
 
10
12
  class AsyncUsersAPI:
11
13
  def __init__(self, requester: AsyncRequesterProtocol) -> None:
12
14
  self._requester = requester
13
15
 
16
+ async def list(
17
+ self,
18
+ *,
19
+ limit: int | None = None,
20
+ cursor: str | None = None,
21
+ time_desc: bool | None = None,
22
+ ) -> ListUsersOutput:
23
+ """List all users in the project.
24
+
25
+ Args:
26
+ limit: Maximum number of users to return. If not provided or 0, all users will be returned. Defaults to None.
27
+ cursor: Cursor for pagination. Defaults to None.
28
+ time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
29
+
30
+ Returns:
31
+ ListUsersOutput containing the list of users and pagination information.
32
+ """
33
+ params = build_params(limit=limit, cursor=cursor, time_desc=time_desc)
34
+ data = await self._requester.request("GET", "/user/ls", params=params or None)
35
+ return ListUsersOutput.model_validate(data)
36
+
37
+ async def get_resources(self, identifier: str) -> GetUserResourcesOutput:
38
+ """Get resource counts for a user.
39
+
40
+ Args:
41
+ identifier: The user identifier string.
42
+
43
+ Returns:
44
+ GetUserResourcesOutput containing counts for Spaces, Sessions, Disks, and Skills.
45
+ """
46
+ data = await self._requester.request(
47
+ "GET", f"/user/{quote(identifier, safe='')}/resources"
48
+ )
49
+ return GetUserResourcesOutput.model_validate(data)
50
+
14
51
  async def delete(self, identifier: str) -> None:
15
52
  """Delete a user and cascade delete all associated resources (Space, Session, Disk, Skill).
16
53
 
@@ -2,10 +2,14 @@
2
2
  Disk and artifact endpoints.
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  import json
6
8
  from collections.abc import Mapping
7
9
  from typing import Any, BinaryIO, cast
8
10
 
11
+ from pydantic import TypeAdapter
12
+
9
13
  from .._utils import build_params
10
14
  from ..client_types import RequesterProtocol
11
15
  from ..types.disk import (
@@ -195,8 +199,85 @@ class DiskArtifactsAPI:
195
199
  *,
196
200
  path: str | None = None,
197
201
  ) -> ListArtifactsResp:
202
+ """List artifacts in a disk at a specific path.
203
+
204
+ Args:
205
+ disk_id: The UUID of the disk.
206
+ path: Directory path to list. Defaults to None (root).
207
+
208
+ Returns:
209
+ ListArtifactsResp containing the list of artifacts.
210
+ """
198
211
  params: dict[str, Any] = {}
199
212
  if path is not None:
200
213
  params["path"] = path
201
214
  data = self._requester.request("GET", f"/disk/{disk_id}/artifact/ls", params=params or None)
202
215
  return ListArtifactsResp.model_validate(data)
216
+
217
+ def grep_artifacts(
218
+ self,
219
+ disk_id: str,
220
+ *,
221
+ query: str,
222
+ limit: int = 100,
223
+ ) -> list[Artifact]:
224
+ """Search artifact content using regex pattern.
225
+
226
+ Args:
227
+ disk_id: The disk ID to search in
228
+ query: Regex pattern to search for in file content
229
+ limit: Maximum number of results (default 100, max 1000)
230
+
231
+ Returns:
232
+ List of matching artifacts
233
+
234
+ Example:
235
+ ```python
236
+ # Search for TODO comments in code
237
+ results = client.disks.artifacts.grep_artifacts(
238
+ disk_id="disk-uuid",
239
+ query="TODO.*bug"
240
+ )
241
+ ```
242
+ """
243
+ params = build_params(query=query, limit=limit)
244
+ data = self._requester.request(
245
+ "GET",
246
+ f"/disk/{disk_id}/artifact/grep",
247
+ params=params
248
+ )
249
+ return TypeAdapter(list[Artifact]).validate_python(data)
250
+
251
+ def glob_artifacts(
252
+ self,
253
+ disk_id: str,
254
+ *,
255
+ query: str,
256
+ limit: int = 100,
257
+ ) -> list[Artifact]:
258
+ """Search artifact paths using glob pattern.
259
+
260
+ Args:
261
+ disk_id: The disk ID to search in
262
+ query: Glob pattern (e.g., '**/*.py', '*.txt')
263
+ limit: Maximum number of results (default 100, max 1000)
264
+
265
+ Returns:
266
+ List of matching artifacts
267
+
268
+ Example:
269
+ ```python
270
+ # Find all Python files
271
+ results = client.disks.artifacts.glob_artifacts(
272
+ disk_id="disk-uuid",
273
+ query="**/*.py"
274
+ )
275
+ ```
276
+ """
277
+ params = build_params(query=query, limit=limit)
278
+ data = self._requester.request(
279
+ "GET",
280
+ f"/disk/{disk_id}/artifact/glob",
281
+ params=params
282
+ )
283
+ return TypeAdapter(list[Artifact]).validate_python(data)
@@ -4,13 +4,50 @@ User management endpoints.
4
4
 
5
5
  from urllib.parse import quote
6
6
 
7
+ from .._utils import build_params
7
8
  from ..client_types import RequesterProtocol
9
+ from ..types.user import GetUserResourcesOutput, ListUsersOutput
8
10
 
9
11
 
10
12
  class UsersAPI:
11
13
  def __init__(self, requester: RequesterProtocol) -> None:
12
14
  self._requester = requester
13
15
 
16
+ def list(
17
+ self,
18
+ *,
19
+ limit: int | None = None,
20
+ cursor: str | None = None,
21
+ time_desc: bool | None = None,
22
+ ) -> ListUsersOutput:
23
+ """List all users in the project.
24
+
25
+ Args:
26
+ limit: Maximum number of users to return. If not provided or 0, all users will be returned. Defaults to None.
27
+ cursor: Cursor for pagination. Defaults to None.
28
+ time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
29
+
30
+ Returns:
31
+ ListUsersOutput containing the list of users and pagination information.
32
+ """
33
+ params = build_params(limit=limit, cursor=cursor, time_desc=time_desc)
34
+ data = self._requester.request("GET", "/user/ls", params=params or None)
35
+ return ListUsersOutput.model_validate(data)
36
+
37
+ def get_resources(self, identifier: str) -> GetUserResourcesOutput:
38
+ """Get resource counts for a user.
39
+
40
+ Args:
41
+ identifier: The user identifier string.
42
+
43
+ Returns:
44
+ GetUserResourcesOutput containing counts for Spaces, Sessions, Disks, and Skills.
45
+ """
46
+ data = self._requester.request(
47
+ "GET", f"/user/{quote(identifier, safe='')}/resources"
48
+ )
49
+ return GetUserResourcesOutput.model_validate(data)
50
+
14
51
  def delete(self, identifier: str) -> None:
15
52
  """Delete a user and cascade delete all associated resources (Space, Session, Disk, Skill).
16
53
 
@@ -45,6 +45,12 @@ from .skill import (
45
45
  Skill,
46
46
  SkillCatalogItem,
47
47
  )
48
+ from .user import (
49
+ GetUserResourcesOutput,
50
+ ListUsersOutput,
51
+ User,
52
+ UserResourceCounts,
53
+ )
48
54
 
49
55
  __all__ = [
50
56
  # Disk types
@@ -88,4 +94,9 @@ __all__ = [
88
94
  "SkillCatalogItem",
89
95
  "ListSkillsOutput",
90
96
  "GetSkillFileResp",
97
+ # User types
98
+ "GetUserResourcesOutput",
99
+ "ListUsersOutput",
100
+ "User",
101
+ "UserResourceCounts",
91
102
  ]
acontext/types/user.py ADDED
@@ -0,0 +1,36 @@
1
+ """Type definitions for user resources."""
2
+
3
+ from pydantic import BaseModel, Field
4
+
5
+
6
+ class User(BaseModel):
7
+ """User model representing a user resource."""
8
+
9
+ id: str = Field(..., description="User UUID")
10
+ project_id: str = Field(..., description="Project UUID")
11
+ identifier: str = Field(..., description="User identifier string")
12
+ created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
13
+ updated_at: str = Field(..., description="ISO 8601 formatted update timestamp")
14
+
15
+
16
+ class ListUsersOutput(BaseModel):
17
+ """Response model for listing users."""
18
+
19
+ items: list[User] = Field(..., description="List of users")
20
+ next_cursor: str | None = Field(None, description="Cursor for pagination")
21
+ has_more: bool = Field(..., description="Whether there are more items")
22
+
23
+
24
+ class UserResourceCounts(BaseModel):
25
+ """Resource counts for a user."""
26
+
27
+ spaces_count: int = Field(..., description="Number of spaces")
28
+ sessions_count: int = Field(..., description="Number of sessions")
29
+ disks_count: int = Field(..., description="Number of disks")
30
+ skills_count: int = Field(..., description="Number of skills")
31
+
32
+
33
+ class GetUserResourcesOutput(BaseModel):
34
+ """Response model for getting user resources."""
35
+
36
+ counts: UserResourceCounts = Field(..., description="Resource counts")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: acontext
3
- Version: 0.0.16
3
+ Version: 0.0.17
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=PAUhm1rBYOdKw3lCD-H9d72emkGL4KoxEvVq4GeS9ig,158
5
5
  acontext/agent/base.py,sha256=kN2KzV6fOlvmMSi_0yu2QqwVLtHh09TznAy_SDtC8iM,2998
6
- acontext/agent/disk.py,sha256=d9sOggIs4da7niB9TaE0ab82_7l0O5n08eOcQxcaYRs,12623
6
+ acontext/agent/disk.py,sha256=dSDjCejP0o4Z4nHJgfKfIXLFZaCA9AFV852Yo9E9GHk,16131
7
7
  acontext/agent/skill.py,sha256=opsOTQyuedqQMlwDXWMVwCwg0u9cyehfyELDEbat3bE,4451
8
8
  acontext/async_client.py,sha256=sqdSNjl3tx8ijoRNYoEwh1Lxdlhfk0zyd-h-xffIJJE,8372
9
9
  acontext/client.py,sha256=3xha-zbHYLwI1njlhmoB_BYK5JIJoXFyrCpvIi63b9o,8097
@@ -18,15 +18,15 @@ acontext/resources/async_sessions.py,sha256=Ld9T8l884r3UuUprRz7MwafSI8BaPfLA0pg0
18
18
  acontext/resources/async_skills.py,sha256=mbEzyUH7S2_jkZ5tfl0FzpHJ7Io3x_biw5FirhokzAQ,5062
19
19
  acontext/resources/async_spaces.py,sha256=b8DNG2L43B6iSgfmH8M-0cxAp681IjSCjw-4alfjV2A,6712
20
20
  acontext/resources/async_tools.py,sha256=RbGaF2kX65Mun-q-Fp5H1J8waWTLIdCOfbdY19jpn1o,1091
21
- acontext/resources/async_users.py,sha256=wqgWIgT4SOAJ0jFN2dXrZ49Fu9KKzP2uV6oVDwfB_Ak,572
21
+ acontext/resources/async_users.py,sha256=m0nK_Luo6Uuvw2azGx8Wg2cXnipnTnyheolr79fX16Y,2020
22
22
  acontext/resources/blocks.py,sha256=HJdAy5HdyTcHCYCPmqNdvApYKZ6aWs-ORIi_wQt3TUM,5447
23
- acontext/resources/disks.py,sha256=3D-8veyWr3crDppyTvTs83FhRGWDmYRBNuKBPDh-sSk,6695
23
+ acontext/resources/disks.py,sha256=pvxs9gdVBothuy0LSkPmuS061nNOgJX3iffypqLHW1Y,9032
24
24
  acontext/resources/sessions.py,sha256=qUoLs01tzmYChHy3kozzGQ3ZeAz_JyWGtCIsVL20BO4,14491
25
25
  acontext/resources/skills.py,sha256=FPp1YWhH85I9BU0fJJC9FbePIbFhyX6j2FYxjPuBEAc,4935
26
26
  acontext/resources/spaces.py,sha256=Ktvkkn3Jj7CZoKMbn6fYuo0zqImoCWj2EnMsnL2q-0A,6571
27
27
  acontext/resources/tools.py,sha256=II_185B0HYKSP43hizE6C1zs7kjkkPLKihuEG8s-DRY,1046
28
- acontext/resources/users.py,sha256=mcoXS-BPiF1Porkpm8ioo1acGPBGZSfHaFfcd1oRWL8,537
29
- acontext/types/__init__.py,sha256=RFrkHI413x7AOk6X2ztu_WcuqNm09xvEzGmE352tDE4,1696
28
+ acontext/resources/users.py,sha256=6xwU7UeMWRIGn6n7LKgsptV9pzYFNWCbJftieptVg6k,1961
29
+ acontext/types/__init__.py,sha256=L6g545qLolIVoo3ltlsOeZOr8T72lTrg9bOK-q1Mw0c,1909
30
30
  acontext/types/block.py,sha256=CzKByunk642rWXNNnh8cx67UzKLKDAxODmC_whwjP90,1078
31
31
  acontext/types/common.py,sha256=5kLwzszlIofz8qZ9-Wj_zcBBiF22mAWgH9uWPkcgWCE,327
32
32
  acontext/types/disk.py,sha256=nMjyXLUre4Xuu_YfBbzzdRQDRxB8qX1Zx9LsNqGCi9E,2223
@@ -34,7 +34,8 @@ acontext/types/session.py,sha256=WIaTiiAw8OujeSnk18Vy_Fn_AffW60pfs-unlPXYuT8,110
34
34
  acontext/types/skill.py,sha256=qBDNysW9ptKX6RcMiZd4PfwWwvcYCzj_dC-6RbXqyx4,2531
35
35
  acontext/types/space.py,sha256=9BkGBYGeQDVwYTmPLoIjMY-IUdQzjrt8I7CXca2_5Vc,2600
36
36
  acontext/types/tool.py,sha256=-mVn-vgk2SENK0Ubt-ZgWFZxKa-ddABqcAgXQ69YY-E,805
37
+ acontext/types/user.py,sha256=JjE0xZDwUAs2BL741U7NINyyPAso64A1YmgMBPqSuvo,1331
37
38
  acontext/uploads.py,sha256=6twnqQOY_eerNuEjeSKsE_3S0IfJUiczXtAy4aXqDl8,1379
38
- acontext-0.0.16.dist-info/WHEEL,sha256=eycQt0QpYmJMLKpE3X9iDk8R04v2ZF0x82ogq-zP6bQ,79
39
- acontext-0.0.16.dist-info/METADATA,sha256=ZBbXvjNXaFKVUN02XUief26BXVQVMHt0-EkcHwV2eU8,859
40
- acontext-0.0.16.dist-info/RECORD,,
39
+ acontext-0.0.17.dist-info/WHEEL,sha256=eycQt0QpYmJMLKpE3X9iDk8R04v2ZF0x82ogq-zP6bQ,79
40
+ acontext-0.0.17.dist-info/METADATA,sha256=Z6rVfzFv3K3o_hSyymhrvdQU2ZGZ20GEwQPjPkNR7Rw,859
41
+ acontext-0.0.17.dist-info/RECORD,,