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.
@@ -1,200 +0,0 @@
1
- """
2
- Spaces endpoints (async).
3
- """
4
-
5
- from collections.abc import Mapping
6
- from typing import Any
7
-
8
- from .._utils import build_params
9
- from ..client_types import AsyncRequesterProtocol
10
- from ..types.space import (
11
- ExperienceConfirmation,
12
- ListExperienceConfirmationsOutput,
13
- ListSpacesOutput,
14
- Space,
15
- SpaceSearchResult,
16
- )
17
-
18
-
19
- class AsyncSpacesAPI:
20
- def __init__(self, requester: AsyncRequesterProtocol) -> None:
21
- self._requester = requester
22
-
23
- async def list(
24
- self,
25
- *,
26
- user: str | None = None,
27
- limit: int | None = None,
28
- cursor: str | None = None,
29
- time_desc: bool | None = None,
30
- ) -> ListSpacesOutput:
31
- """List all spaces in the project.
32
-
33
- Args:
34
- user: Filter by user identifier. Defaults to None.
35
- limit: Maximum number of spaces to return. Defaults to None.
36
- cursor: Cursor for pagination. Defaults to None.
37
- time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
38
-
39
- Returns:
40
- ListSpacesOutput containing the list of spaces and pagination information.
41
- """
42
- params = build_params(user=user, limit=limit, cursor=cursor, time_desc=time_desc)
43
- data = await self._requester.request("GET", "/space", params=params or None)
44
- return ListSpacesOutput.model_validate(data)
45
-
46
- async def create(
47
- self,
48
- *,
49
- user: str | None = None,
50
- configs: Mapping[str, Any] | None = None,
51
- ) -> Space:
52
- """Create a new space.
53
-
54
- Args:
55
- user: Optional user identifier string. Defaults to None.
56
- configs: Optional space configuration dictionary. Defaults to None.
57
-
58
- Returns:
59
- The created Space object.
60
- """
61
- payload: dict[str, Any] = {}
62
- if user is not None:
63
- payload["user"] = user
64
- if configs is not None:
65
- payload["configs"] = configs
66
- data = await self._requester.request("POST", "/space", json_data=payload)
67
- return Space.model_validate(data)
68
-
69
- async def delete(self, space_id: str) -> None:
70
- """Delete a space by its ID.
71
-
72
- Args:
73
- space_id: The UUID of the space to delete.
74
- """
75
- await self._requester.request("DELETE", f"/space/{space_id}")
76
-
77
- async def update_configs(
78
- self,
79
- space_id: str,
80
- *,
81
- configs: Mapping[str, Any],
82
- ) -> None:
83
- """Update space configurations.
84
-
85
- Args:
86
- space_id: The UUID of the space.
87
- configs: Space configuration dictionary.
88
- """
89
- payload = {"configs": configs}
90
- await self._requester.request(
91
- "PUT", f"/space/{space_id}/configs", json_data=payload
92
- )
93
-
94
- async def get_configs(self, space_id: str) -> Space:
95
- """Get space configurations.
96
-
97
- Args:
98
- space_id: The UUID of the space.
99
-
100
- Returns:
101
- Space object containing the configurations.
102
- """
103
- data = await self._requester.request("GET", f"/space/{space_id}/configs")
104
- return Space.model_validate(data)
105
-
106
- async def experience_search(
107
- self,
108
- space_id: str,
109
- *,
110
- query: str,
111
- limit: int | None = None,
112
- mode: str | None = None,
113
- semantic_threshold: float | None = None,
114
- max_iterations: int | None = None,
115
- ) -> SpaceSearchResult:
116
- """Perform experience search within a space.
117
-
118
- This is the most advanced search option that can operate in two modes:
119
- - fast: Quick semantic search (default)
120
- - agentic: Iterative search with AI-powered refinement
121
-
122
- Args:
123
- space_id: The UUID of the space.
124
- query: The search query string.
125
- limit: Maximum number of results to return (1-50, default 10).
126
- mode: Search mode, either "fast" or "agentic" (default "fast").
127
- semantic_threshold: Cosine distance threshold (0=identical, 2=opposite).
128
- max_iterations: Maximum iterations for agentic search (1-100, default 16).
129
-
130
- Returns:
131
- SpaceSearchResult containing cited blocks and optional final answer.
132
- """
133
- params = build_params(
134
- query=query,
135
- limit=limit,
136
- mode=mode,
137
- semantic_threshold=semantic_threshold,
138
- max_iterations=max_iterations,
139
- )
140
- data = await self._requester.request(
141
- "GET", f"/space/{space_id}/experience_search", params=params or None
142
- )
143
- return SpaceSearchResult.model_validate(data)
144
-
145
- async def get_unconfirmed_experiences(
146
- self,
147
- space_id: str,
148
- *,
149
- limit: int | None = None,
150
- cursor: str | None = None,
151
- time_desc: bool | None = None,
152
- ) -> ListExperienceConfirmationsOutput:
153
- """Get all unconfirmed experiences in a space with cursor-based pagination.
154
-
155
- Args:
156
- space_id: The UUID of the space.
157
- limit: Maximum number of confirmations to return (1-200, default 20).
158
- cursor: Cursor for pagination. Use the cursor from the previous response to get the next page.
159
- time_desc: Order by created_at descending if True, ascending if False (default False).
160
-
161
- Returns:
162
- ListExperienceConfirmationsOutput containing the list of experience confirmations and pagination information.
163
- """
164
- params = build_params(limit=limit, cursor=cursor, time_desc=time_desc)
165
- data = await self._requester.request(
166
- "GET",
167
- f"/space/{space_id}/experience_confirmations",
168
- params=params or None,
169
- )
170
- return ListExperienceConfirmationsOutput.model_validate(data)
171
-
172
- async def confirm_experience(
173
- self,
174
- space_id: str,
175
- experience_id: str,
176
- *,
177
- save: bool,
178
- ) -> ExperienceConfirmation | None:
179
- """Confirm an experience confirmation.
180
-
181
- If save is False, delete the row. If save is True, get the data first,
182
- then delete the row.
183
-
184
- Args:
185
- space_id: The UUID of the space.
186
- experience_id: The UUID of the experience confirmation.
187
- save: If True, get data before deleting. If False, just delete.
188
-
189
- Returns:
190
- ExperienceConfirmation object if save is True, None otherwise.
191
- """
192
- payload = {"save": save}
193
- data = await self._requester.request(
194
- "PUT",
195
- f"/space/{space_id}/experience_confirmations/{experience_id}",
196
- json_data=payload,
197
- )
198
- if data is None:
199
- return None
200
- return ExperienceConfirmation.model_validate(data)
@@ -1,163 +0,0 @@
1
- """
2
- Block endpoints.
3
- """
4
-
5
- from collections.abc import Mapping
6
- from typing import Any
7
-
8
- from ..client_types import RequesterProtocol
9
- from ..types.block import Block
10
- from ..types.tool import InsertBlockResponse
11
-
12
-
13
- class BlocksAPI:
14
- def __init__(self, requester: RequesterProtocol) -> None:
15
- self._requester = requester
16
-
17
- 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 = 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
- 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 = self._requester.request("POST", f"/space/{space_id}/block", json_data=payload)
71
- return InsertBlockResponse.model_validate(data)
72
-
73
- 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
- self._requester.request("DELETE", f"/space/{space_id}/block/{block_id}")
81
-
82
- 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 = self._requester.request("GET", f"/space/{space_id}/block/{block_id}/properties")
93
- return Block.model_validate(data)
94
-
95
- 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
- self._requester.request("PUT", f"/space/{space_id}/block/{block_id}/properties", json_data=payload)
122
-
123
- 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
- self._requester.request("PUT", f"/space/{space_id}/block/{block_id}/move", json_data=payload)
150
-
151
- 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
- self._requester.request(
160
- "PUT",
161
- f"/space/{space_id}/block/{block_id}/sort",
162
- json_data={"sort": sort},
163
- )
@@ -1,198 +0,0 @@
1
- """
2
- Spaces endpoints.
3
- """
4
-
5
- from collections.abc import Mapping
6
- from typing import Any
7
-
8
- from .._utils import build_params
9
- from ..client_types import RequesterProtocol
10
- from ..types.space import (
11
- ExperienceConfirmation,
12
- ListExperienceConfirmationsOutput,
13
- ListSpacesOutput,
14
- Space,
15
- SpaceSearchResult,
16
- )
17
-
18
-
19
- class SpacesAPI:
20
- def __init__(self, requester: RequesterProtocol) -> None:
21
- self._requester = requester
22
-
23
- def list(
24
- self,
25
- *,
26
- user: str | None = None,
27
- limit: int | None = None,
28
- cursor: str | None = None,
29
- time_desc: bool | None = None,
30
- ) -> ListSpacesOutput:
31
- """List all spaces in the project.
32
-
33
- Args:
34
- user: Filter by user identifier. Defaults to None.
35
- limit: Maximum number of spaces to return. Defaults to None.
36
- cursor: Cursor for pagination. Defaults to None.
37
- time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
38
-
39
- Returns:
40
- ListSpacesOutput containing the list of spaces and pagination information.
41
- """
42
- params = build_params(user=user, limit=limit, cursor=cursor, time_desc=time_desc)
43
- data = self._requester.request("GET", "/space", params=params or None)
44
- return ListSpacesOutput.model_validate(data)
45
-
46
- def create(
47
- self,
48
- *,
49
- user: str | None = None,
50
- configs: Mapping[str, Any] | None = None,
51
- ) -> Space:
52
- """Create a new space.
53
-
54
- Args:
55
- user: Optional user identifier string. Defaults to None.
56
- configs: Optional space configuration dictionary. Defaults to None.
57
-
58
- Returns:
59
- The created Space object.
60
- """
61
- payload: dict[str, Any] = {}
62
- if user is not None:
63
- payload["user"] = user
64
- if configs is not None:
65
- payload["configs"] = configs
66
- data = self._requester.request("POST", "/space", json_data=payload)
67
- return Space.model_validate(data)
68
-
69
- def delete(self, space_id: str) -> None:
70
- """Delete a space by its ID.
71
-
72
- Args:
73
- space_id: The UUID of the space to delete.
74
- """
75
- self._requester.request("DELETE", f"/space/{space_id}")
76
-
77
- def update_configs(
78
- self,
79
- space_id: str,
80
- *,
81
- configs: Mapping[str, Any],
82
- ) -> None:
83
- """Update space configurations.
84
-
85
- Args:
86
- space_id: The UUID of the space.
87
- configs: Space configuration dictionary.
88
- """
89
- payload = {"configs": configs}
90
- self._requester.request("PUT", f"/space/{space_id}/configs", json_data=payload)
91
-
92
- def get_configs(self, space_id: str) -> Space:
93
- """Get space configurations.
94
-
95
- Args:
96
- space_id: The UUID of the space.
97
-
98
- Returns:
99
- Space object containing the configurations.
100
- """
101
- data = self._requester.request("GET", f"/space/{space_id}/configs")
102
- return Space.model_validate(data)
103
-
104
- def experience_search(
105
- self,
106
- space_id: str,
107
- *,
108
- query: str,
109
- limit: int | None = None,
110
- mode: str | None = None,
111
- semantic_threshold: float | None = None,
112
- max_iterations: int | None = None,
113
- ) -> SpaceSearchResult:
114
- """Perform experience search within a space.
115
-
116
- This is the most advanced search option that can operate in two modes:
117
- - fast: Quick semantic search (default)
118
- - agentic: Iterative search with AI-powered refinement
119
-
120
- Args:
121
- space_id: The UUID of the space.
122
- query: The search query string.
123
- limit: Maximum number of results to return (1-50, default 10).
124
- mode: Search mode, either "fast" or "agentic" (default "fast").
125
- semantic_threshold: Cosine distance threshold (0=identical, 2=opposite).
126
- max_iterations: Maximum iterations for agentic search (1-100, default 16).
127
-
128
- Returns:
129
- SpaceSearchResult containing cited blocks and optional final answer.
130
- """
131
- params = build_params(
132
- query=query,
133
- limit=limit,
134
- mode=mode,
135
- semantic_threshold=semantic_threshold,
136
- max_iterations=max_iterations,
137
- )
138
- data = self._requester.request(
139
- "GET", f"/space/{space_id}/experience_search", params=params or None
140
- )
141
- return SpaceSearchResult.model_validate(data)
142
-
143
- def get_unconfirmed_experiences(
144
- self,
145
- space_id: str,
146
- *,
147
- limit: int | None = None,
148
- cursor: str | None = None,
149
- time_desc: bool | None = None,
150
- ) -> ListExperienceConfirmationsOutput:
151
- """Get all unconfirmed experiences in a space with cursor-based pagination.
152
-
153
- Args:
154
- space_id: The UUID of the space.
155
- limit: Maximum number of confirmations to return (1-200, default 20).
156
- cursor: Cursor for pagination. Use the cursor from the previous response to get the next page.
157
- time_desc: Order by created_at descending if True, ascending if False (default False).
158
-
159
- Returns:
160
- ListExperienceConfirmationsOutput containing the list of experience confirmations and pagination information.
161
- """
162
- params = build_params(limit=limit, cursor=cursor, time_desc=time_desc)
163
- data = self._requester.request(
164
- "GET",
165
- f"/space/{space_id}/experience_confirmations",
166
- params=params or None,
167
- )
168
- return ListExperienceConfirmationsOutput.model_validate(data)
169
-
170
- def confirm_experience(
171
- self,
172
- space_id: str,
173
- experience_id: str,
174
- *,
175
- save: bool,
176
- ) -> ExperienceConfirmation | None:
177
- """Confirm an experience confirmation.
178
-
179
- If save is False, delete the row. If save is True, get the data first,
180
- then delete the row.
181
-
182
- Args:
183
- space_id: The UUID of the space.
184
- experience_id: The UUID of the experience confirmation.
185
- save: If True, get data before deleting. If False, just delete.
186
-
187
- Returns:
188
- ExperienceConfirmation object if save is True, None otherwise.
189
- """
190
- payload = {"save": save}
191
- data = self._requester.request(
192
- "PUT",
193
- f"/space/{space_id}/experience_confirmations/{experience_id}",
194
- json_data=payload,
195
- )
196
- if data is None:
197
- return None
198
- return ExperienceConfirmation.model_validate(data)
acontext/types/block.py DELETED
@@ -1,26 +0,0 @@
1
- """Type definitions for block resources."""
2
-
3
- from typing import Any
4
-
5
- from pydantic import BaseModel, Field
6
-
7
-
8
- class Block(BaseModel):
9
- """Block model representing a block in a space."""
10
-
11
- id: str = Field(..., description="Block UUID")
12
- space_id: str = Field(..., description="Space UUID")
13
- type: str = Field(..., description="Block type: 'page', 'folder', 'text', 'sop', etc.")
14
- parent_id: str | None = Field(None, description="Parent block UUID, optional")
15
- title: str = Field(..., description="Block title")
16
- props: dict[str, Any] = Field(..., description="Block properties dictionary")
17
- sort: int = Field(..., description="Sort order")
18
- is_archived: bool = Field(..., description="Whether the block is archived")
19
- created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
20
- updated_at: str = Field(..., description="ISO 8601 formatted update timestamp")
21
- children: list["Block"] | None = Field(None, description="List of child blocks, optional")
22
-
23
-
24
- # Rebuild model to resolve forward references
25
- Block.model_rebuild()
26
-
acontext/types/space.py DELETED
@@ -1,70 +0,0 @@
1
- """Type definitions for space resources."""
2
-
3
- from typing import Any
4
-
5
- from pydantic import BaseModel, Field
6
-
7
-
8
- class Space(BaseModel):
9
- """Space model representing a space resource."""
10
-
11
- id: str = Field(..., description="Space UUID")
12
- project_id: str = Field(..., description="Project UUID")
13
- user_id: str | None = Field(None, description="User UUID")
14
- configs: dict[str, Any] | None = Field(
15
- None, description="Space configuration dictionary"
16
- )
17
- created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
18
- updated_at: str = Field(..., description="ISO 8601 formatted update timestamp")
19
-
20
-
21
- class ListSpacesOutput(BaseModel):
22
- """Response model for listing spaces."""
23
-
24
- items: list[Space] = Field(..., description="List of spaces")
25
- next_cursor: str | None = Field(None, description="Cursor for pagination")
26
- has_more: bool = Field(..., description="Whether there are more items")
27
-
28
-
29
- class SearchResultBlockItem(BaseModel):
30
- """Search result block item model."""
31
-
32
- block_id: str = Field(..., description="Block UUID")
33
- title: str = Field(..., description="Block title")
34
- type: str = Field(..., description="Block type")
35
- props: dict[str, Any] = Field(..., description="Block properties")
36
- distance: float | None = Field(
37
- None, description="Cosine distance (0=identical, 2=opposite)"
38
- )
39
-
40
-
41
- class SpaceSearchResult(BaseModel):
42
- """Experience search result model."""
43
-
44
- cited_blocks: list[SearchResultBlockItem] = Field(
45
- ..., description="List of cited blocks"
46
- )
47
- final_answer: str | None = Field(None, description="AI-generated final answer")
48
-
49
-
50
- class ExperienceConfirmation(BaseModel):
51
- """Experience confirmation model."""
52
-
53
- id: str = Field(..., description="Experience confirmation UUID")
54
- space_id: str = Field(..., description="Space UUID")
55
- task_id: str | None = Field(None, description="Task UUID (optional)")
56
- experience_data: dict[str, Any] = Field(
57
- ..., description="Experience data dictionary"
58
- )
59
- created_at: str = Field(..., description="ISO 8601 formatted creation timestamp")
60
- updated_at: str = Field(..., description="ISO 8601 formatted update timestamp")
61
-
62
-
63
- class ListExperienceConfirmationsOutput(BaseModel):
64
- """Response model for listing experience confirmations."""
65
-
66
- items: list[ExperienceConfirmation] = Field(
67
- ..., description="List of experience confirmations"
68
- )
69
- next_cursor: str | None = Field(None, description="Cursor for pagination")
70
- has_more: bool = Field(..., description="Whether there are more items")