acontext 0.1.2__py3-none-any.whl → 0.1.4__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.
@@ -12,7 +12,6 @@ from ..types.session import (
12
12
  EditStrategy,
13
13
  GetMessagesOutput,
14
14
  GetTasksOutput,
15
- LearningStatus,
16
15
  ListSessionsOutput,
17
16
  Message,
18
17
  MessageObservingStatus,
@@ -38,8 +37,6 @@ class SessionsAPI:
38
37
  self,
39
38
  *,
40
39
  user: str | None = None,
41
- space_id: str | None = None,
42
- not_connected: bool | None = None,
43
40
  limit: int | None = None,
44
41
  cursor: str | None = None,
45
42
  time_desc: bool | None = None,
@@ -48,8 +45,6 @@ class SessionsAPI:
48
45
 
49
46
  Args:
50
47
  user: Filter by user identifier. Defaults to None.
51
- space_id: Filter sessions by space ID. Defaults to None.
52
- not_connected: Filter sessions that are not connected to a space. Defaults to None.
53
48
  limit: Maximum number of sessions to return. Defaults to None.
54
49
  cursor: Cursor for pagination. Defaults to None.
55
50
  time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
@@ -60,11 +55,8 @@ class SessionsAPI:
60
55
  params: dict[str, Any] = {}
61
56
  if user:
62
57
  params["user"] = user
63
- if space_id:
64
- params["space_id"] = space_id
65
58
  params.update(
66
59
  build_params(
67
- not_connected=not_connected,
68
60
  limit=limit,
69
61
  cursor=cursor,
70
62
  time_desc=time_desc,
@@ -77,7 +69,6 @@ class SessionsAPI:
77
69
  self,
78
70
  *,
79
71
  user: str | None = None,
80
- space_id: str | None = None,
81
72
  disable_task_tracking: bool | None = None,
82
73
  configs: Mapping[str, Any] | None = None,
83
74
  ) -> Session:
@@ -85,7 +76,6 @@ class SessionsAPI:
85
76
 
86
77
  Args:
87
78
  user: Optional user identifier string. Defaults to None.
88
- space_id: Optional space ID to associate with the session. Defaults to None.
89
79
  disable_task_tracking: Whether to disable task tracking for this session. Defaults to None (server default: False).
90
80
  configs: Optional session configuration dictionary. Defaults to None.
91
81
 
@@ -95,8 +85,6 @@ class SessionsAPI:
95
85
  payload: dict[str, Any] = {}
96
86
  if user:
97
87
  payload["user"] = user
98
- if space_id:
99
- payload["space_id"] = space_id
100
88
  if disable_task_tracking is not None:
101
89
  payload["disable_task_tracking"] = disable_task_tracking
102
90
  if configs is not None:
@@ -141,18 +129,6 @@ class SessionsAPI:
141
129
  data = self._requester.request("GET", f"/session/{session_id}/configs")
142
130
  return Session.model_validate(data)
143
131
 
144
- def connect_to_space(self, session_id: str, *, space_id: str) -> None:
145
- """Connect a session to a space.
146
-
147
- Args:
148
- session_id: The UUID of the session.
149
- space_id: The UUID of the space to connect to.
150
- """
151
- payload = {"space_id": space_id}
152
- self._requester.request(
153
- "POST", f"/session/{session_id}/connect_to_space", json_data=payload
154
- )
155
-
156
132
  def get_tasks(
157
133
  self,
158
134
  session_id: str,
@@ -382,23 +358,6 @@ class SessionsAPI:
382
358
  data = self._requester.request("POST", f"/session/{session_id}/flush")
383
359
  return data # type: ignore
384
360
 
385
- def get_learning_status(self, session_id: str) -> LearningStatus:
386
- """Get learning status for a session.
387
-
388
- Returns the count of space digested tasks and not space digested tasks.
389
- If the session is not connected to a space, returns 0 and 0.
390
-
391
- Args:
392
- session_id: The UUID of the session.
393
-
394
- Returns:
395
- LearningStatus object containing space_digested_count and not_space_digested_count.
396
- """
397
- data = self._requester.request(
398
- "GET", f"/session/{session_id}/get_learning_status"
399
- )
400
- return LearningStatus.model_validate(data)
401
-
402
361
  def get_token_counts(self, session_id: str) -> TokenCounts:
403
362
  """Get total token counts for all text and tool-call parts in a session.
404
363
 
@@ -9,6 +9,7 @@ from typing import Any, BinaryIO, cast
9
9
  from .._utils import build_params
10
10
  from ..client_types import RequesterProtocol
11
11
  from ..types.skill import (
12
+ DownloadSkillToSandboxResp,
12
13
  GetSkillFileResp,
13
14
  ListSkillsOutput,
14
15
  Skill,
@@ -135,3 +136,42 @@ class SkillsAPI:
135
136
 
136
137
  data = self._requester.request("GET", endpoint, params=params)
137
138
  return GetSkillFileResp.model_validate(data)
139
+
140
+ def download_to_sandbox(
141
+ self,
142
+ *,
143
+ skill_id: str,
144
+ sandbox_id: str,
145
+ ) -> DownloadSkillToSandboxResp:
146
+ """Download all files from a skill to a sandbox environment.
147
+
148
+ Files are placed at /skills/{skill_name}/.
149
+
150
+ Args:
151
+ skill_id: The UUID of the skill to download.
152
+ sandbox_id: The UUID of the target sandbox.
153
+
154
+ Returns:
155
+ DownloadSkillToSandboxResp containing success status, the directory path
156
+ where the skill was installed, and the skill's name and description.
157
+
158
+ Example:
159
+ ```python
160
+ result = client.skills.download_to_sandbox(
161
+ skill_id="skill-uuid",
162
+ sandbox_id="sandbox-uuid"
163
+ )
164
+ print(f"Success: {result.success}")
165
+ print(f"Skill installed at: {result.dir_path}")
166
+ print(f"Skill name: {result.name}")
167
+ print(f"Description: {result.description}")
168
+ ```
169
+ """
170
+ payload: dict[str, Any] = {"sandbox_id": sandbox_id}
171
+
172
+ data = self._requester.request(
173
+ "POST",
174
+ f"/agent_skills/{skill_id}/download_to_sandbox",
175
+ json_data=payload,
176
+ )
177
+ return DownloadSkillToSandboxResp.model_validate(data)
@@ -41,7 +41,7 @@ class UsersAPI:
41
41
  identifier: The user identifier string.
42
42
 
43
43
  Returns:
44
- GetUserResourcesOutput containing counts for Spaces, Sessions, Disks, and Skills.
44
+ GetUserResourcesOutput containing counts for Sessions, Disks, and Skills.
45
45
  """
46
46
  data = self._requester.request(
47
47
  "GET", f"/user/{quote(identifier, safe='')}/resources"
@@ -49,7 +49,7 @@ class UsersAPI:
49
49
  return GetUserResourcesOutput.model_validate(data)
50
50
 
51
51
  def delete(self, identifier: str) -> None:
52
- """Delete a user and cascade delete all associated resources (Space, Session, Disk, Skill).
52
+ """Delete a user and cascade delete all associated resources (Session, Disk, Skill).
53
53
 
54
54
  Args:
55
55
  identifier: The user identifier string.
@@ -13,7 +13,6 @@ from .session import (
13
13
  Asset,
14
14
  GetMessagesOutput,
15
15
  GetTasksOutput,
16
- LearningStatus,
17
16
  ListSessionsOutput,
18
17
  Message,
19
18
  Part,
@@ -23,18 +22,8 @@ from .session import (
23
22
  TaskData,
24
23
  TokenCounts,
25
24
  )
26
- from .block import Block
27
- from .space import (
28
- ExperienceConfirmation,
29
- ListExperienceConfirmationsOutput,
30
- ListSpacesOutput,
31
- SearchResultBlockItem,
32
- Space,
33
- SpaceSearchResult,
34
- )
35
25
  from .tool import (
36
26
  FlagResponse,
37
- InsertBlockResponse,
38
27
  ToolReferenceData,
39
28
  ToolRenameItem,
40
29
  )
@@ -45,6 +34,14 @@ from .skill import (
45
34
  Skill,
46
35
  SkillCatalogItem,
47
36
  )
37
+ from .sandbox import (
38
+ GeneratedFile,
39
+ GetSandboxLogsOutput,
40
+ HistoryCommand,
41
+ SandboxCommandOutput,
42
+ SandboxLog,
43
+ SandboxRuntimeInfo,
44
+ )
48
45
  from .user import (
49
46
  GetUserResourcesOutput,
50
47
  ListUsersOutput,
@@ -65,7 +62,6 @@ __all__ = [
65
62
  "Asset",
66
63
  "GetMessagesOutput",
67
64
  "GetTasksOutput",
68
- "LearningStatus",
69
65
  "ListSessionsOutput",
70
66
  "Message",
71
67
  "Part",
@@ -74,18 +70,8 @@ __all__ = [
74
70
  "Task",
75
71
  "TaskData",
76
72
  "TokenCounts",
77
- # Space types
78
- "ExperienceConfirmation",
79
- "ListExperienceConfirmationsOutput",
80
- "ListSpacesOutput",
81
- "SearchResultBlockItem",
82
- "Space",
83
- "SpaceSearchResult",
84
- # Block types
85
- "Block",
86
73
  # Tool types
87
74
  "FlagResponse",
88
- "InsertBlockResponse",
89
75
  "ToolReferenceData",
90
76
  "ToolRenameItem",
91
77
  # Skill types
@@ -94,6 +80,13 @@ __all__ = [
94
80
  "SkillCatalogItem",
95
81
  "ListSkillsOutput",
96
82
  "GetSkillFileResp",
83
+ # Sandbox types
84
+ "SandboxCommandOutput",
85
+ "SandboxRuntimeInfo",
86
+ "SandboxLog",
87
+ "HistoryCommand",
88
+ "GeneratedFile",
89
+ "GetSandboxLogsOutput",
97
90
  # User types
98
91
  "GetUserResourcesOutput",
99
92
  "ListUsersOutput",
acontext/types/disk.py CHANGED
@@ -43,8 +43,12 @@ class GetArtifactResp(BaseModel):
43
43
  """Response model for getting an artifact."""
44
44
 
45
45
  artifact: Artifact = Field(..., description="Artifact information")
46
- public_url: str | None = Field(None, description="Presigned URL for downloading the artifact")
47
- content: FileContent | None = Field(None, description="Parsed file content if available")
46
+ public_url: str | None = Field(
47
+ None, description="Presigned URL for downloading the artifact"
48
+ )
49
+ content: FileContent | None = Field(
50
+ None, description="Parsed file content if available"
51
+ )
48
52
 
49
53
 
50
54
  class ListArtifactsResp(BaseModel):
@@ -58,4 +62,3 @@ class UpdateArtifactResp(BaseModel):
58
62
  """Response model for updating an artifact."""
59
63
 
60
64
  artifact: Artifact = Field(..., description="Updated artifact information")
61
-
@@ -0,0 +1,47 @@
1
+ """Type definitions for sandbox resources."""
2
+
3
+ from pydantic import BaseModel, Field
4
+
5
+
6
+ class SandboxRuntimeInfo(BaseModel):
7
+ """Runtime information about a sandbox."""
8
+
9
+ sandbox_id: str = Field(..., description="Sandbox ID")
10
+ sandbox_status: str = Field(..., description="Sandbox status (running, killed, paused, error)")
11
+ sandbox_created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
12
+ sandbox_expires_at: str = Field(..., description="ISO 8601 formatted expiration timestamp")
13
+
14
+
15
+ class SandboxCommandOutput(BaseModel):
16
+ """Output from executing a command in a sandbox."""
17
+
18
+ stdout: str = Field(..., description="Standard output from the command")
19
+ stderr: str = Field(..., description="Standard error from the command")
20
+ exit_code: int = Field(..., description="Exit code of the command")
21
+
22
+
23
+ class HistoryCommand(BaseModel):
24
+ command: str = Field(..., description="The shell command that was executed")
25
+ exit_code: int = Field(..., description="The exit code of the command")
26
+
27
+
28
+ class GeneratedFile(BaseModel):
29
+ sandbox_path: str = Field(..., description="The path to the file in the sandbox")
30
+
31
+
32
+ class SandboxLog(BaseModel):
33
+ id: str = Field(..., description="Sandbox log UUID")
34
+ project_id: str = Field(..., description="Project UUID")
35
+ backend_sandbox_id: str | None = Field(None, description="Backend sandbox ID")
36
+ backend_type: str = Field(..., description="Backend type (e.g., e2b, cloudflare)")
37
+ history_commands: list[HistoryCommand] = Field(..., description="Array of command execution records")
38
+ generated_files: list[GeneratedFile] = Field(..., description="Array of files generated/downloaded from the sandbox")
39
+ will_total_alive_seconds: int = Field(..., description="Total seconds the sandbox will be alive")
40
+ created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
41
+ updated_at: str = Field(..., description="ISO 8601 formatted update timestamp")
42
+
43
+
44
+ class GetSandboxLogsOutput(BaseModel):
45
+ items: list[SandboxLog] = Field(..., description="List of sandbox logs")
46
+ next_cursor: str | None = Field(None, description="Cursor for pagination")
47
+ has_more: bool = Field(..., description="Whether there are more items")
acontext/types/session.py CHANGED
@@ -171,7 +171,6 @@ class Session(BaseModel):
171
171
  disable_task_tracking: bool = Field(
172
172
  False, description="Whether task tracking is disabled for this session"
173
173
  )
174
- space_id: str | None = Field(None, description="Space UUID, optional")
175
174
  configs: dict[str, Any] | None = Field(
176
175
  None, description="Session configuration dictionary"
177
176
  )
@@ -193,9 +192,6 @@ class TaskData(BaseModel):
193
192
  user_preferences: list[str] | None = Field(
194
193
  None, description="List of user preferences related to the task"
195
194
  )
196
- sop_thinking: str | None = Field(
197
- None, description="Standard Operating Procedure thinking notes"
198
- )
199
195
 
200
196
 
201
197
  class Task(BaseModel):
@@ -211,7 +207,6 @@ class Task(BaseModel):
211
207
  description="Task status: 'success', 'failed', 'running', or 'pending'",
212
208
  )
213
209
  is_planning: bool = Field(..., description="Whether the task is in planning phase")
214
- space_digested: bool = Field(..., description="Whether the space has been digested")
215
210
  created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
216
211
  updated_at: str = Field(..., description="ISO 8601 formatted update timestamp")
217
212
 
@@ -280,17 +275,6 @@ class GetTasksOutput(BaseModel):
280
275
  has_more: bool = Field(..., description="Whether there are more items")
281
276
 
282
277
 
283
- class LearningStatus(BaseModel):
284
- """Response model for learning status."""
285
-
286
- space_digested_count: int = Field(
287
- ..., description="Number of tasks that are space digested"
288
- )
289
- not_space_digested_count: int = Field(
290
- ..., description="Number of tasks that are not space digested"
291
- )
292
-
293
-
294
278
  class TokenCounts(BaseModel):
295
279
  """Response model for token counts."""
296
280
 
acontext/types/skill.py CHANGED
@@ -63,3 +63,14 @@ class GetSkillFileResp(BaseModel):
63
63
  None,
64
64
  description="Parsed file content if available (present if file is parseable)",
65
65
  )
66
+
67
+
68
+ class DownloadSkillToSandboxResp(BaseModel):
69
+ """Response model for downloading a skill to sandbox."""
70
+
71
+ success: bool = Field(..., description="Whether the download was successful")
72
+ dir_path: str = Field(
73
+ ..., description="Full path to the skill directory in sandbox"
74
+ )
75
+ name: str = Field(..., description="Skill name")
76
+ description: str = Field(..., description="Skill description")
acontext/types/tool.py CHANGED
@@ -10,12 +10,6 @@ class FlagResponse(BaseModel):
10
10
  errmsg: str = Field(..., description="Error message")
11
11
 
12
12
 
13
- class InsertBlockResponse(BaseModel):
14
- """Response from inserting a block."""
15
-
16
- id: str = Field(..., description="Block UUID")
17
-
18
-
19
13
  class ToolReferenceData(BaseModel):
20
14
  """Tool reference data."""
21
15
 
acontext/types/user.py CHANGED
@@ -24,7 +24,6 @@ class ListUsersOutput(BaseModel):
24
24
  class UserResourceCounts(BaseModel):
25
25
  """Resource counts for a user."""
26
26
 
27
- spaces_count: int = Field(..., description="Number of spaces")
28
27
  sessions_count: int = Field(..., description="Number of sessions")
29
28
  disks_count: int = Field(..., description="Number of disks")
30
29
  skills_count: int = Field(..., description="Number of skills")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: acontext
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: Python SDK for the Acontext API
5
5
  Keywords: acontext,sdk,client,api
6
6
  Requires-Dist: httpx>=0.28.1
@@ -0,0 +1,41 @@
1
+ acontext/__init__.py,sha256=o99U8tML8Xx8EWqNiT9GYJw9a3whtTIUOHg3cyYDcbQ,879
2
+ acontext/_constants.py,sha256=Ikuy_Wz3CPmXjKPLXb4Y580-fe54o1hZ2ZB1Bpw3sFE,363
3
+ acontext/_utils.py,sha256=GKQH45arKh0sDu64u-5jwrII_ctnU_oChYlgR5lRkfE,1250
4
+ acontext/agent/__init__.py,sha256=lx5HqeVDfIxkbGfAt0ju8hkk8EPsgFvKmMrQzjNXR8w,213
5
+ acontext/agent/base.py,sha256=BDTqfqkPrPzvQIH_llOX6S_bkcDw3E30J5x9yd47Q6g,3526
6
+ acontext/agent/disk.py,sha256=q-3DRkLcQLfdAXADJM3GPo6reWPzhKQrnyBiZdBZvIY,22775
7
+ acontext/agent/prompts.py,sha256=Y20C78f9PacjpyN_I_urQBDzoiAeVSXE4Cj5BV67Qhg,4865
8
+ acontext/agent/sandbox.py,sha256=eGN_yBTo3jWNhxTZMi-Rkr0ALJ6YP5WZbF8u0oBPn2Y,18209
9
+ acontext/agent/skill.py,sha256=uB7teH7OAk4Cy6pOLRCJFBi5KZbyMMgZSLEt77TLB20,12880
10
+ acontext/agent/text_editor.py,sha256=HsmDexX2wqacaeIwkCyDrojZDQiI9mr4krt6phSKS7g,13247
11
+ acontext/async_client.py,sha256=WjqW7ruMtlYTBlk6PQ1-1yhjFSBBxGqI3oxrfEqqIpQ,8471
12
+ acontext/client.py,sha256=XggELxXU9-8BcAcHOoiqQZypfPmkhe7SyJ3plHq-A9M,8217
13
+ acontext/client_types.py,sha256=oR6lSDMjEERx0mIVOpKaTXbEu_lfoxe3fDpzA-ALE-8,1063
14
+ acontext/errors.py,sha256=W9i7_t46q9kbci3XAyZiyQhS154d4R9rSon3na-gjgs,1296
15
+ acontext/messages.py,sha256=oNRZStfhcPFt6DPOfs_-Q7R1Xui6dOMr3wmpmC8pzvE,2310
16
+ acontext/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ acontext/resources/__init__.py,sha256=i2_12EUfxo2z-dgMu8dyAsEiT9nf2P00voN2_vMZ2K8,843
18
+ acontext/resources/async_disks.py,sha256=rc8hSdVsZ1UbrK2kwxmEMZyP0aEMsvjyZ70cYddpiF8,12051
19
+ acontext/resources/async_sandboxes.py,sha256=qkpEhmUUUrq_C1mVSVyUzBvxzBdq6BvL9e76FXyk19M,2850
20
+ acontext/resources/async_sessions.py,sha256=wBUUIDUvMqe_mdR3l_3HuPfEWUcq65SOJLc5mKTu0nI,14691
21
+ acontext/resources/async_skills.py,sha256=eRn3NjBhR6_6GmEyZO_nKc0OnHgR_TeIHxqGX_73lwo,5999
22
+ acontext/resources/async_tools.py,sha256=RbGaF2kX65Mun-q-Fp5H1J8waWTLIdCOfbdY19jpn1o,1091
23
+ acontext/resources/async_users.py,sha256=CjW_Xz-UnNf449Hr1j3YeGgtIVZi2ePY5-r7Uj3wMIc,2005
24
+ acontext/resources/disks.py,sha256=YyAzm6A00T4A3dI8YTEAOxwm6bnCnp8gWIoZ4lLGN5w,11859
25
+ acontext/resources/sandboxes.py,sha256=2E9Ls15t3FQ9LBZOnk0--IjQhxwZGTPkbpS5zcnOJSo,2779
26
+ acontext/resources/sessions.py,sha256=yaFwiWsShM4HVguwsM-Mp9HHJohl84R-LOFp8uGJUyU,14454
27
+ acontext/resources/skills.py,sha256=CZFgJhRDtGlbDcTBKNxFkG4DlqoaJb0c_ymfV12QKdM,5930
28
+ acontext/resources/tools.py,sha256=II_185B0HYKSP43hizE6C1zs7kjkkPLKihuEG8s-DRY,1046
29
+ acontext/resources/users.py,sha256=vZfBHd2ARmd9d5d8n5rLaMUT5z2bMO82k7OcqMaFqxk,1946
30
+ acontext/types/__init__.py,sha256=rZHoT0gWIQ576J2mGqhyqWu4Uh8jn0HINdhNJwbjZ8U,1725
31
+ acontext/types/common.py,sha256=5kLwzszlIofz8qZ9-Wj_zcBBiF22mAWgH9uWPkcgWCE,327
32
+ acontext/types/disk.py,sha256=jdQqQ8HF3cwl_Y1dh98TOXZKfcdN_gSzaSrCE8PKT-0,2250
33
+ acontext/types/sandbox.py,sha256=vbgpwjbVjjY3uwXxSbOP8IfC65lhkJ_4BYA19dqj5FE,2248
34
+ acontext/types/session.py,sha256=WqhEtrg1jwknIiQ9TipUeLONS4bY_J_C7Xd_TrYlsWg,11003
35
+ acontext/types/skill.py,sha256=v7OAvtkwTeZAkLG7NQMcwFoSJ4g-HDWjPZ4EoMyU3mk,2779
36
+ acontext/types/tool.py,sha256=UlX6JIGRKd96vPayOkyi6pGwFi6w9GwWwAxr4BcqVts,670
37
+ acontext/types/user.py,sha256=dBzHCqULSJ3Sqw7T8nA0U8Sctz76Pd0hm1qsHvtEIBQ,1264
38
+ acontext/uploads.py,sha256=6twnqQOY_eerNuEjeSKsE_3S0IfJUiczXtAy4aXqDl8,1379
39
+ acontext-0.1.4.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
40
+ acontext-0.1.4.dist-info/METADATA,sha256=wvxyJ9Rq48wlqsbGdig2RELL5RvXYGtVENosB7a0nGU,888
41
+ acontext-0.1.4.dist-info/RECORD,,
@@ -1,164 +0,0 @@
1
- """
2
- Block endpoints (async).
3
- """
4
-
5
- from collections.abc import Mapping
6
- from typing import Any
7
-
8
- from ..client_types import AsyncRequesterProtocol
9
- from ..types.block import Block
10
- from ..types.tool import InsertBlockResponse
11
-
12
-
13
- class AsyncBlocksAPI:
14
- def __init__(self, requester: AsyncRequesterProtocol) -> None:
15
- self._requester = requester
16
-
17
- async def list(
18
- self,
19
- space_id: str,
20
- *,
21
- parent_id: str | None = None,
22
- block_type: str | None = None,
23
- ) -> list[Block]:
24
- """List blocks in a space.
25
-
26
- Args:
27
- space_id: The UUID of the space.
28
- parent_id: Filter blocks by parent ID. Defaults to None.
29
- block_type: Filter blocks by type (e.g., "page", "folder", "text", "sop"). Defaults to None.
30
-
31
- Returns:
32
- List of Block objects.
33
- """
34
- params: dict[str, Any] = {}
35
- if parent_id is not None:
36
- params["parent_id"] = parent_id
37
- if block_type is not None:
38
- params["type"] = block_type
39
- data = await self._requester.request("GET", f"/space/{space_id}/block", params=params or None)
40
- return [Block.model_validate(item) for item in data]
41
-
42
- async def create(
43
- self,
44
- space_id: str,
45
- *,
46
- block_type: str,
47
- parent_id: str | None = None,
48
- title: str | None = None,
49
- props: Mapping[str, Any] | None = None,
50
- ) -> InsertBlockResponse:
51
- """Create a new block in a space.
52
-
53
- Args:
54
- space_id: The UUID of the space.
55
- block_type: The type of block (e.g., "page", "folder", "text", "sop").
56
- parent_id: Optional parent block ID. Defaults to None.
57
- title: Optional block title. Defaults to None.
58
- props: Optional block properties dictionary. Defaults to None.
59
-
60
- Returns:
61
- InsertBlockResponse containing the new block ID.
62
- """
63
- payload: dict[str, Any] = {"type": block_type}
64
- if parent_id is not None:
65
- payload["parent_id"] = parent_id
66
- if title is not None:
67
- payload["title"] = title
68
- if props is not None:
69
- payload["props"] = props
70
- data = await self._requester.request("POST", f"/space/{space_id}/block", json_data=payload)
71
- return InsertBlockResponse.model_validate(data)
72
-
73
- async def delete(self, space_id: str, block_id: str) -> None:
74
- """Delete a block by its ID.
75
-
76
- Args:
77
- space_id: The UUID of the space.
78
- block_id: The UUID of the block to delete.
79
- """
80
- await self._requester.request("DELETE", f"/space/{space_id}/block/{block_id}")
81
-
82
- async def get_properties(self, space_id: str, block_id: str) -> Block:
83
- """Get block properties.
84
-
85
- Args:
86
- space_id: The UUID of the space.
87
- block_id: The UUID of the block.
88
-
89
- Returns:
90
- Block object containing the properties.
91
- """
92
- data = await self._requester.request("GET", f"/space/{space_id}/block/{block_id}/properties")
93
- return Block.model_validate(data)
94
-
95
- async def update_properties(
96
- self,
97
- space_id: str,
98
- block_id: str,
99
- *,
100
- title: str | None = None,
101
- props: Mapping[str, Any] | None = None,
102
- ) -> None:
103
- """Update block properties.
104
-
105
- Args:
106
- space_id: The UUID of the space.
107
- block_id: The UUID of the block.
108
- title: Optional block title. Defaults to None.
109
- props: Optional block properties dictionary. Defaults to None.
110
-
111
- Raises:
112
- ValueError: If both title and props are None.
113
- """
114
- payload: dict[str, Any] = {}
115
- if title is not None:
116
- payload["title"] = title
117
- if props is not None:
118
- payload["props"] = props
119
- if not payload:
120
- raise ValueError("title or props must be provided")
121
- await self._requester.request("PUT", f"/space/{space_id}/block/{block_id}/properties", json_data=payload)
122
-
123
- async def move(
124
- self,
125
- space_id: str,
126
- block_id: str,
127
- *,
128
- parent_id: str | None = None,
129
- sort: int | None = None,
130
- ) -> None:
131
- """Move a block by updating its parent or sort order.
132
-
133
- Args:
134
- space_id: The UUID of the space.
135
- block_id: The UUID of the block to move.
136
- parent_id: Optional new parent block ID. Defaults to None.
137
- sort: Optional new sort order. Defaults to None.
138
-
139
- Raises:
140
- ValueError: If both parent_id and sort are None.
141
- """
142
- payload: dict[str, Any] = {}
143
- if parent_id is not None:
144
- payload["parent_id"] = parent_id
145
- if sort is not None:
146
- payload["sort"] = sort
147
- if not payload:
148
- raise ValueError("parent_id or sort must be provided")
149
- await self._requester.request("PUT", f"/space/{space_id}/block/{block_id}/move", json_data=payload)
150
-
151
- async def update_sort(self, space_id: str, block_id: str, *, sort: int) -> None:
152
- """Update block sort order.
153
-
154
- Args:
155
- space_id: The UUID of the space.
156
- block_id: The UUID of the block.
157
- sort: The new sort order.
158
- """
159
- await self._requester.request(
160
- "PUT",
161
- f"/space/{space_id}/block/{block_id}/sort",
162
- json_data={"sort": sort},
163
- )
164
-