acontext 0.0.16__py3-none-any.whl → 0.0.18__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
 
acontext/agent/skill.py CHANGED
@@ -2,15 +2,67 @@
2
2
  Skill tools for agent operations.
3
3
  """
4
4
 
5
- from dataclasses import dataclass
5
+ from dataclasses import dataclass, field
6
6
 
7
7
  from .base import BaseContext, BaseTool, BaseToolPool
8
8
  from ..client import AcontextClient
9
+ from ..types.skill import Skill
9
10
 
10
11
 
11
12
  @dataclass
12
13
  class SkillContext(BaseContext):
14
+ """Context for skill tools with preloaded skill name mapping."""
15
+
13
16
  client: AcontextClient
17
+ skills: dict[str, Skill] = field(default_factory=dict)
18
+
19
+ @classmethod
20
+ def create(cls, client: AcontextClient, skill_ids: list[str]) -> "SkillContext":
21
+ """Create a SkillContext by preloading skills from a list of skill IDs.
22
+
23
+ Args:
24
+ client: The Acontext client instance.
25
+ skill_ids: List of skill UUIDs to preload.
26
+
27
+ Returns:
28
+ SkillContext with preloaded skills mapped by name.
29
+
30
+ Raises:
31
+ ValueError: If duplicate skill names are found.
32
+ """
33
+ skills: dict[str, Skill] = {}
34
+ for skill_id in skill_ids:
35
+ skill = client.skills.get(skill_id)
36
+ if skill.name in skills:
37
+ raise ValueError(
38
+ f"Duplicate skill name '{skill.name}' found. "
39
+ f"Existing ID: {skills[skill.name].id}, New ID: {skill.id}"
40
+ )
41
+ skills[skill.name] = skill
42
+ return cls(client=client, skills=skills)
43
+
44
+ def get_skill(self, skill_name: str) -> Skill:
45
+ """Get a skill by name from the preloaded skills.
46
+
47
+ Args:
48
+ skill_name: The name of the skill.
49
+
50
+ Returns:
51
+ The Skill object.
52
+
53
+ Raises:
54
+ ValueError: If the skill is not found in the context.
55
+ """
56
+ if skill_name not in self.skills:
57
+ available = ", ".join(self.skills.keys()) if self.skills else "[none]"
58
+ raise ValueError(
59
+ f"Skill '{skill_name}' not found in context. Available skills: {available}"
60
+ )
61
+ return self.skills[skill_name]
62
+
63
+ def list_skill_names(self) -> list[str]:
64
+ """Return list of available skill names in this context."""
65
+ return list(self.skills.keys())
14
66
 
15
67
 
16
68
  class GetSkillTool(BaseTool):
@@ -23,37 +75,41 @@ class GetSkillTool(BaseTool):
23
75
  @property
24
76
  def description(self) -> str:
25
77
  return (
26
- "Get a skill by its name. Return the skill information including the relative paths of the files and their mime type categories"
78
+ "Get a skill by its name. Returns the skill information including "
79
+ "the relative paths of the files and their mime type categories."
27
80
  )
28
81
 
29
82
  @property
30
83
  def arguments(self) -> dict:
31
84
  return {
32
- "name": {
85
+ "skill_name": {
33
86
  "type": "string",
34
- "description": "The name of the skill (unique within project).",
87
+ "description": "The name of the skill.",
35
88
  },
36
89
  }
37
90
 
38
91
  @property
39
92
  def required_arguments(self) -> list[str]:
40
- return ["name"]
93
+ return ["skill_name"]
41
94
 
42
95
  def execute(self, ctx: SkillContext, llm_arguments: dict) -> str:
43
96
  """Get a skill by name."""
44
- name = llm_arguments.get("name")
97
+ skill_name = llm_arguments.get("skill_name")
45
98
 
46
- if not name:
47
- raise ValueError("name is required")
99
+ if not skill_name:
100
+ raise ValueError("skill_name is required")
48
101
 
49
- skill = ctx.client.skills.get_by_name(name)
102
+ skill = ctx.get_skill(skill_name)
50
103
 
51
104
  file_count = len(skill.file_index)
52
-
105
+
53
106
  # Format all files with path and MIME type
54
107
  if skill.file_index:
55
108
  file_list = "\n".join(
56
- [f" - {file_info.path} ({file_info.mime})" for file_info in skill.file_index]
109
+ [
110
+ f" - {file_info.path} ({file_info.mime})"
111
+ for file_info in skill.file_index
112
+ ]
57
113
  )
58
114
  else:
59
115
  file_list = " [NO FILES]"
@@ -62,9 +118,7 @@ class GetSkillTool(BaseTool):
62
118
  f"Skill: {skill.name} (ID: {skill.id})\n"
63
119
  f"Description: {skill.description}\n"
64
120
  f"Files: {file_count} file(s)\n"
65
- f"{file_list}\n"
66
- f"Created: {skill.created_at}\n"
67
- f"Updated: {skill.updated_at}"
121
+ f"{file_list}"
68
122
  )
69
123
 
70
124
 
@@ -78,7 +132,9 @@ class GetSkillFileTool(BaseTool):
78
132
  @property
79
133
  def description(self) -> str:
80
134
  return (
81
- "Get a file from a skill by name. The file_path should be a relative path within the skill (e.g., 'scripts/extract_text.json'). "
135
+ "Get a file from a skill by name. The file_path should be a relative "
136
+ "path within the skill (e.g., 'scripts/extract_text.json')."
137
+ "Tips: SKILL.md is the first file you should read to understand the full picture of this skill's content."
82
138
  )
83
139
 
84
140
  @property
@@ -108,18 +164,22 @@ class GetSkillFileTool(BaseTool):
108
164
  file_path = llm_arguments.get("file_path")
109
165
  expire = llm_arguments.get("expire")
110
166
 
111
- if not file_path:
112
- raise ValueError("file_path is required")
113
167
  if not skill_name:
114
168
  raise ValueError("skill_name is required")
169
+ if not file_path:
170
+ raise ValueError("file_path is required")
171
+
172
+ skill = ctx.get_skill(skill_name)
115
173
 
116
- result = ctx.client.skills.get_file_by_name(
117
- skill_name=skill_name,
174
+ result = ctx.client.skills.get_file(
175
+ skill_id=skill.id,
118
176
  file_path=file_path,
119
177
  expire=expire,
120
178
  )
121
179
 
122
- output_parts = [f"File '{result.path}' (MIME: {result.mime}) from skill '{skill_name}':"]
180
+ output_parts = [
181
+ f"File '{result.path}' (MIME: {result.mime}) from skill '{skill_name}':"
182
+ ]
123
183
 
124
184
  if result.content:
125
185
  output_parts.append(f"\nContent (type: {result.content.type}):")
@@ -127,7 +187,9 @@ class GetSkillFileTool(BaseTool):
127
187
 
128
188
  if result.url:
129
189
  expire_seconds = expire if expire is not None else 900
130
- output_parts.append(f"\nDownload URL (expires in {expire_seconds} seconds):")
190
+ output_parts.append(
191
+ f"\nDownload URL (expires in {expire_seconds} seconds):"
192
+ )
131
193
  output_parts.append(result.url)
132
194
 
133
195
  if not result.content and not result.url:
@@ -136,13 +198,56 @@ class GetSkillFileTool(BaseTool):
136
198
  return "\n".join(output_parts)
137
199
 
138
200
 
201
+ class ListSkillsTool(BaseTool):
202
+ """Tool for listing available skills in the context."""
203
+
204
+ @property
205
+ def name(self) -> str:
206
+ return "list_skills"
207
+
208
+ @property
209
+ def description(self) -> str:
210
+ return "List all available skills in the current context with their names and descriptions."
211
+
212
+ @property
213
+ def arguments(self) -> dict:
214
+ return {}
215
+
216
+ @property
217
+ def required_arguments(self) -> list[str]:
218
+ return []
219
+
220
+ def execute(self, ctx: SkillContext, llm_arguments: dict) -> str:
221
+ """List all available skills."""
222
+ if not ctx.skills:
223
+ return "No skills available in the current context."
224
+
225
+ skill_list = []
226
+ for skill_name, skill in ctx.skills.items():
227
+ skill_list.append(f"- {skill_name}: {skill.description}")
228
+
229
+ return f"Available skills ({len(ctx.skills)}):\n" + "\n".join(skill_list)
230
+
231
+
139
232
  class SkillToolPool(BaseToolPool):
140
233
  """Tool pool for skill operations on Acontext skills."""
141
234
 
142
- def format_context(self, client: AcontextClient) -> SkillContext:
143
- return SkillContext(client=client)
235
+ def format_context(
236
+ self, client: AcontextClient, skill_ids: list[str]
237
+ ) -> SkillContext:
238
+ """Create a SkillContext by preloading skills from a list of skill IDs.
239
+
240
+ Args:
241
+ client: The Acontext client instance.
242
+ skill_ids: List of skill UUIDs to preload.
243
+
244
+ Returns:
245
+ SkillContext with preloaded skills mapped by name.
246
+ """
247
+ return SkillContext.create(client=client, skill_ids=skill_ids)
144
248
 
145
249
 
146
250
  SKILL_TOOLS = SkillToolPool()
251
+ SKILL_TOOLS.add_tool(ListSkillsTool())
147
252
  SKILL_TOOLS.add_tool(GetSkillTool())
148
253
  SKILL_TOOLS.add_tool(GetSkillFileTool())
@@ -12,8 +12,6 @@ from ..types.skill import (
12
12
  GetSkillFileResp,
13
13
  ListSkillsOutput,
14
14
  Skill,
15
- SkillCatalogItem,
16
- _ListSkillsResponse,
17
15
  )
18
16
  from ..uploads import FileUpload, normalize_file_upload
19
17
 
@@ -84,31 +82,19 @@ class AsyncSkillsAPI:
84
82
  data = await self._requester.request(
85
83
  "GET", "/agent_skills", params=params or None
86
84
  )
87
- api_response = _ListSkillsResponse.model_validate(data)
88
-
89
- # Convert to catalog format (name and description only)
90
- return ListSkillsOutput(
91
- items=[
92
- SkillCatalogItem(name=skill.name, description=skill.description)
93
- for skill in api_response.items
94
- ],
95
- next_cursor=api_response.next_cursor,
96
- has_more=api_response.has_more,
97
- )
85
+ # Pydantic ignores extra fields, so ListSkillsOutput directly extracts name/description
86
+ return ListSkillsOutput.model_validate(data)
98
87
 
99
- async def get_by_name(self, name: str) -> Skill:
100
- """Get a skill by its name.
88
+ async def get(self, skill_id: str) -> Skill:
89
+ """Get a skill by its ID.
101
90
 
102
91
  Args:
103
- name: The name of the skill (unique within project).
92
+ skill_id: The UUID of the skill.
104
93
 
105
94
  Returns:
106
- Skill containing the skill information.
95
+ Skill containing the full skill information including file_index.
107
96
  """
108
- params = {"name": name}
109
- data = await self._requester.request(
110
- "GET", "/agent_skills/by_name", params=params
111
- )
97
+ data = await self._requester.request("GET", f"/agent_skills/{skill_id}")
112
98
  return Skill.model_validate(data)
113
99
 
114
100
  async def delete(self, skill_id: str) -> None:
@@ -119,32 +105,31 @@ class AsyncSkillsAPI:
119
105
  """
120
106
  await self._requester.request("DELETE", f"/agent_skills/{skill_id}")
121
107
 
122
- async def get_file_by_name(
108
+ async def get_file(
123
109
  self,
124
110
  *,
125
- skill_name: str,
111
+ skill_id: str,
126
112
  file_path: str,
127
113
  expire: int | None = None,
128
114
  ) -> GetSkillFileResp:
129
- """Get a file from a skill by name.
115
+ """Get a file from a skill by skill ID.
130
116
 
131
117
  The backend automatically returns content for parseable text files, or a presigned URL
132
118
  for non-parseable files (binary, images, etc.).
133
119
 
134
120
  Args:
135
- skill_name: The name of the skill.
121
+ skill_id: The UUID of the skill.
136
122
  file_path: Relative path to the file within the skill (e.g., 'scripts/extract_text.json').
137
123
  expire: URL expiration time in seconds. Defaults to 900 (15 minutes).
138
124
 
139
125
  Returns:
140
126
  GetSkillFileResp containing the file path, MIME type, and either content or URL.
141
127
  """
142
- endpoint = f"/agent_skills/by_name/{skill_name}/file"
128
+ endpoint = f"/agent_skills/{skill_id}/file"
143
129
 
144
- params = {"file_path": file_path}
130
+ params: dict[str, Any] = {"file_path": file_path}
145
131
  if expire is not None:
146
132
  params["expire"] = expire
147
133
 
148
134
  data = await self._requester.request("GET", endpoint, params=params)
149
135
  return GetSkillFileResp.model_validate(data)
150
-
@@ -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)
@@ -12,8 +12,6 @@ from ..types.skill import (
12
12
  GetSkillFileResp,
13
13
  ListSkillsOutput,
14
14
  Skill,
15
- SkillCatalogItem,
16
- _ListSkillsResponse,
17
15
  )
18
16
  from ..uploads import FileUpload, normalize_file_upload
19
17
 
@@ -25,9 +23,11 @@ class SkillsAPI:
25
23
  def create(
26
24
  self,
27
25
  *,
28
- file: FileUpload
29
- | tuple[str, BinaryIO | bytes]
30
- | tuple[str, BinaryIO | bytes, str],
26
+ file: (
27
+ FileUpload
28
+ | tuple[str, BinaryIO | bytes]
29
+ | tuple[str, BinaryIO | bytes, str]
30
+ ),
31
31
  user: str | None = None,
32
32
  meta: Mapping[str, Any] | None = None,
33
33
  ) -> Skill:
@@ -80,31 +80,23 @@ class SkillsAPI:
80
80
  along with pagination information (next_cursor and has_more).
81
81
  """
82
82
  effective_limit = limit if limit is not None else 100
83
- params = build_params(user=user, limit=effective_limit, cursor=cursor, time_desc=time_desc)
84
- data = self._requester.request("GET", "/agent_skills", params=params or None)
85
- api_response = _ListSkillsResponse.model_validate(data)
86
-
87
- # Convert to catalog format (name and description only)
88
- return ListSkillsOutput(
89
- items=[
90
- SkillCatalogItem(name=skill.name, description=skill.description)
91
- for skill in api_response.items
92
- ],
93
- next_cursor=api_response.next_cursor,
94
- has_more=api_response.has_more,
83
+ params = build_params(
84
+ user=user, limit=effective_limit, cursor=cursor, time_desc=time_desc
95
85
  )
86
+ data = self._requester.request("GET", "/agent_skills", params=params or None)
87
+ # Pydantic ignores extra fields, so ListSkillsOutput directly extracts name/description
88
+ return ListSkillsOutput.model_validate(data)
96
89
 
97
- def get_by_name(self, name: str) -> Skill:
98
- """Get a skill by its name.
90
+ def get(self, skill_id: str) -> Skill:
91
+ """Get a skill by its ID.
99
92
 
100
93
  Args:
101
- name: The name of the skill (unique within project).
94
+ skill_id: The UUID of the skill.
102
95
 
103
96
  Returns:
104
- Skill containing the skill information.
97
+ Skill containing the full skill information including file_index.
105
98
  """
106
- params = {"name": name}
107
- data = self._requester.request("GET", "/agent_skills/by_name", params=params)
99
+ data = self._requester.request("GET", f"/agent_skills/{skill_id}")
108
100
  return Skill.model_validate(data)
109
101
 
110
102
  def delete(self, skill_id: str) -> None:
@@ -115,32 +107,31 @@ class SkillsAPI:
115
107
  """
116
108
  self._requester.request("DELETE", f"/agent_skills/{skill_id}")
117
109
 
118
- def get_file_by_name(
110
+ def get_file(
119
111
  self,
120
112
  *,
121
- skill_name: str,
113
+ skill_id: str,
122
114
  file_path: str,
123
115
  expire: int | None = None,
124
116
  ) -> GetSkillFileResp:
125
- """Get a file from a skill by name.
117
+ """Get a file from a skill by skill ID.
126
118
 
127
119
  The backend automatically returns content for parseable text files, or a presigned URL
128
120
  for non-parseable files (binary, images, etc.).
129
121
 
130
122
  Args:
131
- skill_name: The name of the skill.
123
+ skill_id: The UUID of the skill.
132
124
  file_path: Relative path to the file within the skill (e.g., 'scripts/extract_text.json').
133
125
  expire: URL expiration time in seconds. Defaults to 900 (15 minutes).
134
126
 
135
127
  Returns:
136
128
  GetSkillFileResp containing the file path, MIME type, and either content or URL.
137
129
  """
138
- endpoint = f"/agent_skills/by_name/{skill_name}/file"
130
+ endpoint = f"/agent_skills/{skill_id}/file"
139
131
 
140
- params = {"file_path": file_path}
132
+ params: dict[str, Any] = {"file_path": file_path}
141
133
  if expire is not None:
142
134
  params["expire"] = expire
143
135
 
144
136
  data = self._requester.request("GET", endpoint, params=params)
145
137
  return GetSkillFileResp.model_validate(data)
146
-
@@ -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/skill.py CHANGED
@@ -24,9 +24,7 @@ class Skill(BaseModel):
24
24
  file_index: list[FileInfo] = Field(
25
25
  ..., description="List of file information (path and MIME type) in the skill"
26
26
  )
27
- meta: dict[str, Any] | None = Field(
28
- None, description="Custom metadata dictionary"
29
- )
27
+ meta: dict[str, Any] | None = Field(None, description="Custom metadata dictionary")
30
28
  created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
31
29
  updated_at: str = Field(..., description="ISO 8601 formatted update timestamp")
32
30
 
@@ -39,7 +37,11 @@ class SkillCatalogItem(BaseModel):
39
37
 
40
38
 
41
39
  class ListSkillsOutput(BaseModel):
42
- """Response model for listing skills (catalog format with name and description only)."""
40
+ """Response model for listing skills (catalog format with name and description only).
41
+
42
+ Pydantic ignores extra fields, so this directly parses API responses
43
+ and extracts only name/description from each item.
44
+ """
43
45
 
44
46
  items: list[SkillCatalogItem] = Field(
45
47
  ..., description="List of skills with name and description"
@@ -48,22 +50,16 @@ class ListSkillsOutput(BaseModel):
48
50
  has_more: bool = Field(..., description="Whether there are more items")
49
51
 
50
52
 
51
- class _ListSkillsResponse(BaseModel):
52
- """Internal response model for API pagination (full Skill objects).
53
-
54
- This is used internally to parse the raw API response before converting
55
- to the catalog format (ListSkillsOutput).
56
- """
57
- items: list[Skill]
58
- next_cursor: str | None = None
59
- has_more: bool = False
60
-
61
-
62
53
  class GetSkillFileResp(BaseModel):
63
54
  """Response model for getting a skill file."""
64
55
 
65
56
  path: str = Field(..., description="File path")
66
57
  mime: str = Field(..., description="MIME type of the file")
67
- url: str | None = Field(None, description="Presigned URL for downloading the file (present if file is not parseable)")
68
- content: FileContent | None = Field(None, description="Parsed file content if available (present if file is parseable)")
69
-
58
+ url: str | None = Field(
59
+ None,
60
+ description="Presigned URL for downloading the file (present if file is not parseable)",
61
+ )
62
+ content: FileContent | None = Field(
63
+ None,
64
+ description="Parsed file content if available (present if file is parseable)",
65
+ )
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.18
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,8 +3,8 @@ 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
7
- acontext/agent/skill.py,sha256=opsOTQyuedqQMlwDXWMVwCwg0u9cyehfyELDEbat3bE,4451
6
+ acontext/agent/disk.py,sha256=dSDjCejP0o4Z4nHJgfKfIXLFZaCA9AFV852Yo9E9GHk,16131
7
+ acontext/agent/skill.py,sha256=iRdIqBw8-t5A2iiOuzq4cgj4SDjYQ_xFJA3VbRhrhoA,7792
8
8
  acontext/async_client.py,sha256=sqdSNjl3tx8ijoRNYoEwh1Lxdlhfk0zyd-h-xffIJJE,8372
9
9
  acontext/client.py,sha256=3xha-zbHYLwI1njlhmoB_BYK5JIJoXFyrCpvIi63b9o,8097
10
10
  acontext/client_types.py,sha256=uVBWzLbZyXrqkljG49ojdQL_xX6N3n_HGt4Bs_TEE48,987
@@ -15,26 +15,27 @@ acontext/resources/__init__.py,sha256=Oww11t9hmwdNFK2nC8YW9mf4BBSz5YLPAXAWLlZuNT
15
15
  acontext/resources/async_blocks.py,sha256=e_iJpgcAdwS2tXQ16MMCnySlddp5JV3BadN_EyqZSF4,5555
16
16
  acontext/resources/async_disks.py,sha256=rwcRwQ79ZYbMMWAj5YDDpKQmfAIOl9M3CTYxOZTy_UU,6830
17
17
  acontext/resources/async_sessions.py,sha256=Ld9T8l884r3UuUprRz7MwafSI8BaPfLA0pg0dPfNM1A,14363
18
- acontext/resources/async_skills.py,sha256=mbEzyUH7S2_jkZ5tfl0FzpHJ7Io3x_biw5FirhokzAQ,5062
18
+ acontext/resources/async_skills.py,sha256=VoeqO9Z6E7qPCE2tMJaO7coONaCKCoLJRANQ5yWVbiE,4666
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
- acontext/resources/skills.py,sha256=FPp1YWhH85I9BU0fJJC9FbePIbFhyX6j2FYxjPuBEAc,4935
25
+ acontext/resources/skills.py,sha256=ZECLUfy4QWHnzk9nnq1VvEeFTx-u7NvEhECfbq5Reiw,4615
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
33
33
  acontext/types/session.py,sha256=WIaTiiAw8OujeSnk18Vy_Fn_AffW60pfs-unlPXYuT8,11076
34
- acontext/types/skill.py,sha256=qBDNysW9ptKX6RcMiZd4PfwWwvcYCzj_dC-6RbXqyx4,2531
34
+ acontext/types/skill.py,sha256=VlLp5NpsJSpyoQTlTuV6jJ4G6ArHr1SDpcqEmFkHyeY,2364
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.18.dist-info/WHEEL,sha256=eycQt0QpYmJMLKpE3X9iDk8R04v2ZF0x82ogq-zP6bQ,79
40
+ acontext-0.0.18.dist-info/METADATA,sha256=Cx7aF0w2eFg2ovJ4FyaW-NGg7NW-dnS5iPPRPJ7lZh8,859
41
+ acontext-0.0.18.dist-info/RECORD,,