codebuddy-agent-sdk 0.3.7__py3-none-manylinux_2_17_x86_64.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.
@@ -0,0 +1,395 @@
1
+ """Type definitions for CodeBuddy Agent SDK."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Awaitable, Callable
6
+ from dataclasses import dataclass, field
7
+ from pathlib import Path
8
+ from typing import TYPE_CHECKING, Any, Literal, NotRequired, TypedDict
9
+
10
+ if TYPE_CHECKING:
11
+ from .mcp.types import SdkMcpServer
12
+
13
+ # ============= AskUserQuestion Types =============
14
+
15
+
16
+ @dataclass
17
+ class AskUserQuestionOption:
18
+ """Option for AskUserQuestion tool."""
19
+
20
+ label: str
21
+ description: str
22
+
23
+
24
+ @dataclass
25
+ class AskUserQuestionQuestion:
26
+ """Question for AskUserQuestion tool."""
27
+
28
+ question: str
29
+ header: str
30
+ options: list[AskUserQuestionOption]
31
+ multi_select: bool
32
+
33
+
34
+ @dataclass
35
+ class AskUserQuestionInput:
36
+ """Input for AskUserQuestion tool."""
37
+
38
+ questions: list[AskUserQuestionQuestion]
39
+ answers: dict[str, str] | None = None
40
+
41
+
42
+ # ============= Permission Types =============
43
+
44
+
45
+ @dataclass
46
+ class CanUseToolOptions:
47
+ """Options passed to canUseTool callback."""
48
+
49
+ tool_use_id: str
50
+ signal: Any | None = None
51
+ agent_id: str | None = None
52
+ suggestions: list[dict[str, Any]] | None = None
53
+ blocked_path: str | None = None
54
+ decision_reason: str | None = None
55
+
56
+
57
+ @dataclass
58
+ class PermissionResultAllow:
59
+ """Allow permission result."""
60
+
61
+ updated_input: dict[str, Any]
62
+ behavior: Literal["allow"] = "allow"
63
+ updated_permissions: list[dict[str, Any]] | None = None
64
+
65
+
66
+ @dataclass
67
+ class PermissionResultDeny:
68
+ """Deny permission result."""
69
+
70
+ message: str
71
+ behavior: Literal["deny"] = "deny"
72
+ interrupt: bool = False
73
+
74
+
75
+ PermissionResult = PermissionResultAllow | PermissionResultDeny
76
+
77
+ # CanUseTool callback type
78
+ CanUseTool = Callable[
79
+ [str, dict[str, Any], CanUseToolOptions],
80
+ Awaitable[PermissionResult],
81
+ ]
82
+
83
+
84
+ # Permission modes
85
+ PermissionMode = Literal["default", "acceptEdits", "plan", "bypassPermissions"]
86
+
87
+ # Hook events
88
+ HookEvent = (
89
+ Literal["PreToolUse"]
90
+ | Literal["PostToolUse"]
91
+ | Literal["UserPromptSubmit"]
92
+ | Literal["Stop"]
93
+ | Literal["SubagentStop"]
94
+ | Literal["PreCompact"]
95
+ | Literal["unstable_Checkpoint"]
96
+ )
97
+
98
+
99
+ # ============= Checkpoint Types =============
100
+
101
+
102
+ @dataclass
103
+ class FileVersion:
104
+ """File version information for checkpoint snapshots."""
105
+
106
+ file_path: str
107
+ """Absolute path to the file."""
108
+
109
+ version: int
110
+ """Version number of this snapshot."""
111
+
112
+ backup_time: int
113
+ """Timestamp when the backup was created."""
114
+
115
+ backup_file_name: str | None = None
116
+ """Backup file name in the checkpoint storage."""
117
+
118
+
119
+ @dataclass
120
+ class CheckpointFileChangeStats:
121
+ """Statistics about file changes in a checkpoint."""
122
+
123
+ files: list[str]
124
+ """List of changed file paths."""
125
+
126
+ additions: int
127
+ """Total lines added."""
128
+
129
+ deletions: int
130
+ """Total lines deleted."""
131
+
132
+
133
+ @dataclass
134
+ class Checkpoint:
135
+ """Checkpoint data structure containing file snapshots and change statistics."""
136
+
137
+ file_snapshots: dict[str, FileVersion]
138
+ """Map of file paths to their version information."""
139
+
140
+ id: str | None = None
141
+ """Unique identifier for this checkpoint."""
142
+
143
+ parent_id: str | None = None
144
+ """Parent checkpoint ID (for checkpoint chain)."""
145
+
146
+ logical_parent_id: str | None = None
147
+ """Logical parent ID (used after compaction)."""
148
+
149
+ label: str | None = None
150
+ """Human-readable label (usually the user's prompt)."""
151
+
152
+ created_at: int | None = None
153
+ """Timestamp when the checkpoint was created."""
154
+
155
+ file_change_stats: CheckpointFileChangeStats | None = None
156
+ """File change statistics for this checkpoint."""
157
+
158
+
159
+ # Setting sources
160
+ SettingSource = Literal["user", "project", "local"]
161
+
162
+
163
+ # Agent definition
164
+ @dataclass
165
+ class AgentDefinition:
166
+ """Agent definition configuration."""
167
+
168
+ description: str
169
+ prompt: str
170
+ tools: list[str] | None = None
171
+ disallowed_tools: list[str] | None = None
172
+ model: str | None = None
173
+
174
+
175
+ # Content block types
176
+ @dataclass
177
+ class TextBlock:
178
+ """Text content block."""
179
+
180
+ text: str
181
+
182
+
183
+ @dataclass
184
+ class ThinkingBlock:
185
+ """Thinking content block."""
186
+
187
+ thinking: str
188
+ signature: str
189
+
190
+
191
+ @dataclass
192
+ class ToolUseBlock:
193
+ """Tool use content block."""
194
+
195
+ id: str
196
+ name: str
197
+ input: dict[str, Any]
198
+
199
+
200
+ @dataclass
201
+ class ToolResultBlock:
202
+ """Tool result content block."""
203
+
204
+ tool_use_id: str
205
+ content: str | list[dict[str, Any]] | None = None
206
+ is_error: bool | None = None
207
+
208
+
209
+ ContentBlock = TextBlock | ThinkingBlock | ToolUseBlock | ToolResultBlock
210
+
211
+
212
+ # Message types
213
+ @dataclass
214
+ class UserMessage:
215
+ """User message."""
216
+
217
+ content: str | list[ContentBlock]
218
+ uuid: str | None = None
219
+ parent_tool_use_id: str | None = None
220
+
221
+
222
+ @dataclass
223
+ class AssistantMessage:
224
+ """Assistant message with content blocks."""
225
+
226
+ content: list[ContentBlock]
227
+ model: str
228
+ parent_tool_use_id: str | None = None
229
+ error: str | None = None
230
+
231
+
232
+ @dataclass
233
+ class SystemMessage:
234
+ """System message with metadata."""
235
+
236
+ subtype: str
237
+ data: dict[str, Any]
238
+
239
+
240
+ @dataclass
241
+ class ResultMessage:
242
+ """Result message with cost and usage information."""
243
+
244
+ subtype: str
245
+ duration_ms: int
246
+ duration_api_ms: int
247
+ is_error: bool
248
+ num_turns: int
249
+ session_id: str
250
+ total_cost_usd: float | None = None
251
+ usage: dict[str, Any] | None = None
252
+ result: str | None = None
253
+ errors: list[str] | None = None
254
+
255
+
256
+ @dataclass
257
+ class StreamEvent:
258
+ """Stream event for partial message updates during streaming."""
259
+
260
+ uuid: str
261
+ session_id: str
262
+ event: dict[str, Any]
263
+ parent_tool_use_id: str | None = None
264
+
265
+
266
+ @dataclass
267
+ class ErrorMessage:
268
+ """Error message from CLI."""
269
+
270
+ error: str
271
+ session_id: str | None = None
272
+
273
+
274
+ Message = (
275
+ UserMessage | AssistantMessage | SystemMessage | ResultMessage | StreamEvent | ErrorMessage
276
+ )
277
+
278
+
279
+ # Hook types
280
+ class HookContext(TypedDict):
281
+ """Context information for hook callbacks."""
282
+
283
+ signal: Any | None
284
+
285
+
286
+ class SyncHookJSONOutput(TypedDict):
287
+ """Synchronous hook output with control and decision fields."""
288
+
289
+ continue_: NotRequired[bool]
290
+ suppressOutput: NotRequired[bool]
291
+ stopReason: NotRequired[str]
292
+ decision: NotRequired[Literal["block"]]
293
+ reason: NotRequired[str]
294
+
295
+
296
+ HookJSONOutput = SyncHookJSONOutput
297
+
298
+ HookCallback = Callable[
299
+ [Any, str | None, HookContext],
300
+ Awaitable[HookJSONOutput],
301
+ ]
302
+
303
+
304
+ @dataclass
305
+ class HookMatcher:
306
+ """Hook matcher configuration."""
307
+
308
+ matcher: str | None = None
309
+ hooks: list[HookCallback] = field(default_factory=list)
310
+ timeout: float | None = None
311
+
312
+
313
+ # MCP Server config
314
+ class McpStdioServerConfig(TypedDict):
315
+ """MCP stdio server configuration."""
316
+
317
+ type: NotRequired[Literal["stdio"]]
318
+ command: str
319
+ args: NotRequired[list[str]]
320
+ env: NotRequired[dict[str, str]]
321
+
322
+
323
+ class McpSdkServerConfig(TypedDict):
324
+ """
325
+ SDK MCP Server configuration - for servers running within the SDK process.
326
+ Created via create_sdk_mcp_server().
327
+ """
328
+
329
+ type: Literal["sdk"]
330
+ name: str
331
+ server: SdkMcpServer
332
+
333
+
334
+ McpServerConfig = McpStdioServerConfig | McpSdkServerConfig
335
+
336
+
337
+ # System prompt configuration
338
+ @dataclass
339
+ class AppendSystemPrompt:
340
+ """Append to the default system prompt."""
341
+
342
+ append: str
343
+
344
+
345
+ # Main configuration
346
+ @dataclass
347
+ class CodeBuddyAgentOptions:
348
+ """Query options for CodeBuddy Agent SDK."""
349
+
350
+ session_id: str | None = None
351
+ """Custom session ID for the conversation."""
352
+
353
+ allowed_tools: list[str] = field(default_factory=list)
354
+ """
355
+ List of tool names that are auto-allowed without prompting for permission.
356
+ These tools will execute automatically without asking the user for approval.
357
+ """
358
+
359
+ disallowed_tools: list[str] = field(default_factory=list)
360
+ """
361
+ List of tool names that are disallowed. When the model attempts to use
362
+ these tools, the request will be denied. MCP tools matching this list
363
+ are also filtered from the model's context.
364
+ """
365
+
366
+ system_prompt: str | AppendSystemPrompt | None = None
367
+ """
368
+ System prompt configuration.
369
+
370
+ - `str`: Override the entire system prompt
371
+ - `AppendSystemPrompt`: Append to the default system prompt
372
+ """
373
+
374
+ mcp_servers: dict[str, McpServerConfig] | str | Path = field(default_factory=dict)
375
+ permission_mode: PermissionMode | None = None
376
+ continue_conversation: bool = False
377
+ resume: str | None = None
378
+ max_turns: int | None = None
379
+ model: str | None = None
380
+ fallback_model: str | None = None
381
+ cwd: str | Path | None = None
382
+ codebuddy_code_path: str | Path | None = None
383
+ env: dict[str, str] = field(default_factory=dict)
384
+ extra_args: dict[str, str | None] = field(default_factory=dict)
385
+ stderr: Callable[[str], None] | None = None
386
+ hooks: dict[HookEvent, list[HookMatcher]] | None = None
387
+ include_partial_messages: bool = False
388
+ fork_session: bool = False
389
+ agents: dict[str, AgentDefinition] | None = None
390
+ setting_sources: list[SettingSource] | None = None
391
+ can_use_tool: CanUseTool | None = None
392
+ """
393
+ Custom permission handler callback.
394
+ Called when a tool requires permission approval.
395
+ """
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: codebuddy-agent-sdk
3
+ Version: 0.3.7
4
+ Summary: CodeBuddy Code SDK for Python
5
+ Author-email: ninoyi <ninoyi@tencent.com>
6
+ Keywords: agent,ai,codebuddy,sdk
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: typing-extensions>=4.0.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: mypy>=1.10.0; extra == 'dev'
18
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
19
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
20
+ Requires-Dist: ruff>=0.4.0; extra == 'dev'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # CodeBuddy Agent SDK for Python
24
+
25
+ SDK for building AI agents with CodeBuddy Code's capabilities. Programmatically interact with AI to build autonomous agents that can understand codebases, edit files, and execute workflows.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ # Using uv (recommended)
31
+ uv add codebuddy-agent-sdk
32
+
33
+ # Using pip
34
+ pip install codebuddy-agent-sdk
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ```python
40
+ import asyncio
41
+ from codebuddy_agent_sdk import query
42
+
43
+ async def main():
44
+ async for message in query(
45
+ prompt="What files are in this directory?",
46
+ permission_mode="bypassPermissions",
47
+ ):
48
+ if message.type == "assistant":
49
+ for block in message.content:
50
+ if hasattr(block, "text"):
51
+ print(block.text)
52
+
53
+ asyncio.run(main())
54
+ ```
55
+
56
+ ## API Reference
57
+
58
+ ### `query(prompt, **options)`
59
+
60
+ Create a query to interact with the agent.
61
+
62
+ ```python
63
+ async for message in query(
64
+ prompt="Your prompt here",
65
+ model="sonnet", # Model to use
66
+ permission_mode="bypassPermissions", # Permission mode
67
+ max_turns=10, # Maximum conversation turns
68
+ cwd="/path/to/project", # Working directory
69
+ ):
70
+ # Handle message
71
+ pass
72
+ ```
73
+
74
+ ### Message Types
75
+
76
+ - `system` - Session initialization info
77
+ - `assistant` - Agent responses (text, tool calls)
78
+ - `result` - Query completion status
79
+
80
+ ## Related Links
81
+
82
+ - [CodeBuddy Code CLI](https://www.npmjs.com/package/@tencent-ai/codebuddy-code)
83
+ - [Documentation](https://cnb.cool/codebuddy/codebuddy-code/-/blob/main/docs)
84
+ - [Issues](https://cnb.cool/codebuddy/codebuddy-code/-/issues)
85
+
86
+ ## Feedback
87
+
88
+ - Submit issues at [Issues](https://cnb.cool/codebuddy/codebuddy-code/-/issues)
89
+ - Contact: codebuddy@tencent.com
@@ -0,0 +1,20 @@
1
+ codebuddy_agent_sdk/__init__.py,sha256=X-lmIUF0yxDX_JdnsMn9-CfjP4hJygU4H6mceNWKt_Q,2849
2
+ codebuddy_agent_sdk/_binary.py,sha256=rQFj2B__X7zHMxFazp_0vgXQFsqPi578f8g4jSkLUBc,4338
3
+ codebuddy_agent_sdk/_errors.py,sha256=bLmyebUowNlbUomXyuS1L6J6ZbwHohvzqH_1GmN4_oM,1248
4
+ codebuddy_agent_sdk/_message_parser.py,sha256=vtyeuwIFdl9Wz1WrWEg7G6E3OECDZT4G6bvpH15Q3VY,3504
5
+ codebuddy_agent_sdk/_version.py,sha256=xxkf8qhShJPiXZ9CdxfSLw3MainNv6xdkCRQnH024nk,74
6
+ codebuddy_agent_sdk/client.py,sha256=n2l-k4AgupmpfA6Lb9odrDeNr_TzYN58HY97PwRFqZE,13696
7
+ codebuddy_agent_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ codebuddy_agent_sdk/query.py,sha256=wimOqtdPHFXn8kMFdOiPirozse8cyHHr5Iq43Tln19o,10809
9
+ codebuddy_agent_sdk/types.py,sha256=emublgsgl2JhTzGINFII83hJ0b-O_y0ZhMl_BpgHT-w,9059
10
+ codebuddy_agent_sdk/bin/codebuddy,sha256=_NV_KcPrxvqnKa5SQBAR-e6OeStGfbKXEvEtXDiwpT4,119702490
11
+ codebuddy_agent_sdk/mcp/__init__.py,sha256=0aCmHN0MnMCCUU0bdTWBRlxAblnxA-vR5Og0y3BA480,764
12
+ codebuddy_agent_sdk/mcp/create_sdk_mcp_server.py,sha256=ig0b0ghf0T8GGjltFBRSmQSTFsaJ6fBI8S1Pjupqhps,4959
13
+ codebuddy_agent_sdk/mcp/sdk_control_server_transport.py,sha256=CIG3h5gULubGcQPHPVd-GG9cLswwVDfgDlLba6ZPQbs,2944
14
+ codebuddy_agent_sdk/mcp/types.py,sha256=CPEBUW5vCt93cBgu3HvAacXMsa5FdRWwWxPeicQ0PWw,8578
15
+ codebuddy_agent_sdk/transport/__init__.py,sha256=zv_8OJHgnWjCInqOiu3GOFby4XVGvDwICHpOsymOlko,166
16
+ codebuddy_agent_sdk/transport/base.py,sha256=dOCV1Oqn6nSE3oiM9ocq49C2Rv_bk9_j2c1685bp4zE,820
17
+ codebuddy_agent_sdk/transport/subprocess.py,sha256=4V6eXR8OJyaNdhDl2B-DSWLcDVdm2m0qc48VG3MzmPQ,12190
18
+ codebuddy_agent_sdk-0.3.7.dist-info/METADATA,sha256=8E4UWqGe-6M3pswtFtXiQhkriNhYAwY56-VlVboSPQY,2538
19
+ codebuddy_agent_sdk-0.3.7.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
20
+ codebuddy_agent_sdk-0.3.7.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-manylinux_2_17_x86_64