codebuddy-agent-sdk 0.1.16__py3-none-musllinux_1_1_aarch64.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.
- codebuddy_agent_sdk/__init__.py +97 -0
- codebuddy_agent_sdk/_binary.py +148 -0
- codebuddy_agent_sdk/_errors.py +39 -0
- codebuddy_agent_sdk/_message_parser.py +112 -0
- codebuddy_agent_sdk/_version.py +3 -0
- codebuddy_agent_sdk/bin/codebuddy +0 -0
- codebuddy_agent_sdk/client.py +298 -0
- codebuddy_agent_sdk/py.typed +0 -0
- codebuddy_agent_sdk/query.py +316 -0
- codebuddy_agent_sdk/transport/__init__.py +6 -0
- codebuddy_agent_sdk/transport/base.py +24 -0
- codebuddy_agent_sdk/transport/subprocess.py +167 -0
- codebuddy_agent_sdk/types.py +303 -0
- codebuddy_agent_sdk-0.1.16.dist-info/METADATA +89 -0
- codebuddy_agent_sdk-0.1.16.dist-info/RECORD +16 -0
- codebuddy_agent_sdk-0.1.16.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"""Type definitions for CodeBuddy Agent SDK."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Awaitable, Callable
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Literal, NotRequired, TypedDict
|
|
7
|
+
|
|
8
|
+
# ============= AskUserQuestion Types =============
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class AskUserQuestionOption:
|
|
13
|
+
"""Option for AskUserQuestion tool."""
|
|
14
|
+
|
|
15
|
+
label: str
|
|
16
|
+
description: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class AskUserQuestionQuestion:
|
|
21
|
+
"""Question for AskUserQuestion tool."""
|
|
22
|
+
|
|
23
|
+
question: str
|
|
24
|
+
header: str
|
|
25
|
+
options: list[AskUserQuestionOption]
|
|
26
|
+
multi_select: bool
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class AskUserQuestionInput:
|
|
31
|
+
"""Input for AskUserQuestion tool."""
|
|
32
|
+
|
|
33
|
+
questions: list[AskUserQuestionQuestion]
|
|
34
|
+
answers: dict[str, str] | None = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# ============= Permission Types =============
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class CanUseToolOptions:
|
|
42
|
+
"""Options passed to canUseTool callback."""
|
|
43
|
+
|
|
44
|
+
tool_use_id: str
|
|
45
|
+
signal: Any | None = None
|
|
46
|
+
agent_id: str | None = None
|
|
47
|
+
suggestions: list[dict[str, Any]] | None = None
|
|
48
|
+
blocked_path: str | None = None
|
|
49
|
+
decision_reason: str | None = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class PermissionResultAllow:
|
|
54
|
+
"""Allow permission result."""
|
|
55
|
+
|
|
56
|
+
updated_input: dict[str, Any]
|
|
57
|
+
behavior: Literal["allow"] = "allow"
|
|
58
|
+
updated_permissions: list[dict[str, Any]] | None = None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class PermissionResultDeny:
|
|
63
|
+
"""Deny permission result."""
|
|
64
|
+
|
|
65
|
+
message: str
|
|
66
|
+
behavior: Literal["deny"] = "deny"
|
|
67
|
+
interrupt: bool = False
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
PermissionResult = PermissionResultAllow | PermissionResultDeny
|
|
71
|
+
|
|
72
|
+
# CanUseTool callback type
|
|
73
|
+
CanUseTool = Callable[
|
|
74
|
+
[str, dict[str, Any], CanUseToolOptions],
|
|
75
|
+
Awaitable[PermissionResult],
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Permission modes
|
|
80
|
+
PermissionMode = Literal["default", "acceptEdits", "plan", "bypassPermissions"]
|
|
81
|
+
|
|
82
|
+
# Hook events
|
|
83
|
+
HookEvent = (
|
|
84
|
+
Literal["PreToolUse"]
|
|
85
|
+
| Literal["PostToolUse"]
|
|
86
|
+
| Literal["UserPromptSubmit"]
|
|
87
|
+
| Literal["Stop"]
|
|
88
|
+
| Literal["SubagentStop"]
|
|
89
|
+
| Literal["PreCompact"]
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# Setting sources
|
|
93
|
+
SettingSource = Literal["user", "project", "local"]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# Agent definition
|
|
97
|
+
@dataclass
|
|
98
|
+
class AgentDefinition:
|
|
99
|
+
"""Agent definition configuration."""
|
|
100
|
+
|
|
101
|
+
description: str
|
|
102
|
+
prompt: str
|
|
103
|
+
tools: list[str] | None = None
|
|
104
|
+
disallowed_tools: list[str] | None = None
|
|
105
|
+
model: str | None = None
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# Content block types
|
|
109
|
+
@dataclass
|
|
110
|
+
class TextBlock:
|
|
111
|
+
"""Text content block."""
|
|
112
|
+
|
|
113
|
+
text: str
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@dataclass
|
|
117
|
+
class ThinkingBlock:
|
|
118
|
+
"""Thinking content block."""
|
|
119
|
+
|
|
120
|
+
thinking: str
|
|
121
|
+
signature: str
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@dataclass
|
|
125
|
+
class ToolUseBlock:
|
|
126
|
+
"""Tool use content block."""
|
|
127
|
+
|
|
128
|
+
id: str
|
|
129
|
+
name: str
|
|
130
|
+
input: dict[str, Any]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@dataclass
|
|
134
|
+
class ToolResultBlock:
|
|
135
|
+
"""Tool result content block."""
|
|
136
|
+
|
|
137
|
+
tool_use_id: str
|
|
138
|
+
content: str | list[dict[str, Any]] | None = None
|
|
139
|
+
is_error: bool | None = None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
ContentBlock = TextBlock | ThinkingBlock | ToolUseBlock | ToolResultBlock
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# Message types
|
|
146
|
+
@dataclass
|
|
147
|
+
class UserMessage:
|
|
148
|
+
"""User message."""
|
|
149
|
+
|
|
150
|
+
content: str | list[ContentBlock]
|
|
151
|
+
uuid: str | None = None
|
|
152
|
+
parent_tool_use_id: str | None = None
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@dataclass
|
|
156
|
+
class AssistantMessage:
|
|
157
|
+
"""Assistant message with content blocks."""
|
|
158
|
+
|
|
159
|
+
content: list[ContentBlock]
|
|
160
|
+
model: str
|
|
161
|
+
parent_tool_use_id: str | None = None
|
|
162
|
+
error: str | None = None
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@dataclass
|
|
166
|
+
class SystemMessage:
|
|
167
|
+
"""System message with metadata."""
|
|
168
|
+
|
|
169
|
+
subtype: str
|
|
170
|
+
data: dict[str, Any]
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@dataclass
|
|
174
|
+
class ResultMessage:
|
|
175
|
+
"""Result message with cost and usage information."""
|
|
176
|
+
|
|
177
|
+
subtype: str
|
|
178
|
+
duration_ms: int
|
|
179
|
+
duration_api_ms: int
|
|
180
|
+
is_error: bool
|
|
181
|
+
num_turns: int
|
|
182
|
+
session_id: str
|
|
183
|
+
total_cost_usd: float | None = None
|
|
184
|
+
usage: dict[str, Any] | None = None
|
|
185
|
+
result: str | None = None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@dataclass
|
|
189
|
+
class StreamEvent:
|
|
190
|
+
"""Stream event for partial message updates during streaming."""
|
|
191
|
+
|
|
192
|
+
uuid: str
|
|
193
|
+
session_id: str
|
|
194
|
+
event: dict[str, Any]
|
|
195
|
+
parent_tool_use_id: str | None = None
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
Message = UserMessage | AssistantMessage | SystemMessage | ResultMessage | StreamEvent
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
# Hook types
|
|
202
|
+
class HookContext(TypedDict):
|
|
203
|
+
"""Context information for hook callbacks."""
|
|
204
|
+
|
|
205
|
+
signal: Any | None
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class SyncHookJSONOutput(TypedDict):
|
|
209
|
+
"""Synchronous hook output with control and decision fields."""
|
|
210
|
+
|
|
211
|
+
continue_: NotRequired[bool]
|
|
212
|
+
suppressOutput: NotRequired[bool]
|
|
213
|
+
stopReason: NotRequired[str]
|
|
214
|
+
decision: NotRequired[Literal["block"]]
|
|
215
|
+
reason: NotRequired[str]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
HookJSONOutput = SyncHookJSONOutput
|
|
219
|
+
|
|
220
|
+
HookCallback = Callable[
|
|
221
|
+
[Any, str | None, HookContext],
|
|
222
|
+
Awaitable[HookJSONOutput],
|
|
223
|
+
]
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@dataclass
|
|
227
|
+
class HookMatcher:
|
|
228
|
+
"""Hook matcher configuration."""
|
|
229
|
+
|
|
230
|
+
matcher: str | None = None
|
|
231
|
+
hooks: list[HookCallback] = field(default_factory=list)
|
|
232
|
+
timeout: float | None = None
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
# MCP Server config
|
|
236
|
+
class McpStdioServerConfig(TypedDict):
|
|
237
|
+
"""MCP stdio server configuration."""
|
|
238
|
+
|
|
239
|
+
type: NotRequired[Literal["stdio"]]
|
|
240
|
+
command: str
|
|
241
|
+
args: NotRequired[list[str]]
|
|
242
|
+
env: NotRequired[dict[str, str]]
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
McpServerConfig = McpStdioServerConfig
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# System prompt configuration
|
|
249
|
+
@dataclass
|
|
250
|
+
class AppendSystemPrompt:
|
|
251
|
+
"""Append to the default system prompt."""
|
|
252
|
+
|
|
253
|
+
append: str
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
# Main configuration
|
|
257
|
+
@dataclass
|
|
258
|
+
class CodeBuddyAgentOptions:
|
|
259
|
+
"""Query options for CodeBuddy Agent SDK."""
|
|
260
|
+
|
|
261
|
+
allowed_tools: list[str] = field(default_factory=list)
|
|
262
|
+
"""
|
|
263
|
+
List of tool names that are auto-allowed without prompting for permission.
|
|
264
|
+
These tools will execute automatically without asking the user for approval.
|
|
265
|
+
"""
|
|
266
|
+
|
|
267
|
+
disallowed_tools: list[str] = field(default_factory=list)
|
|
268
|
+
"""
|
|
269
|
+
List of tool names that are disallowed. When the model attempts to use
|
|
270
|
+
these tools, the request will be denied. MCP tools matching this list
|
|
271
|
+
are also filtered from the model's context.
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
system_prompt: str | AppendSystemPrompt | None = None
|
|
275
|
+
"""
|
|
276
|
+
System prompt configuration.
|
|
277
|
+
|
|
278
|
+
- `str`: Override the entire system prompt
|
|
279
|
+
- `AppendSystemPrompt`: Append to the default system prompt
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
mcp_servers: dict[str, McpServerConfig] | str | Path = field(default_factory=dict)
|
|
283
|
+
permission_mode: PermissionMode | None = None
|
|
284
|
+
continue_conversation: bool = False
|
|
285
|
+
resume: str | None = None
|
|
286
|
+
max_turns: int | None = None
|
|
287
|
+
model: str | None = None
|
|
288
|
+
fallback_model: str | None = None
|
|
289
|
+
cwd: str | Path | None = None
|
|
290
|
+
codebuddy_code_path: str | Path | None = None
|
|
291
|
+
env: dict[str, str] = field(default_factory=dict)
|
|
292
|
+
extra_args: dict[str, str | None] = field(default_factory=dict)
|
|
293
|
+
stderr: Callable[[str], None] | None = None
|
|
294
|
+
hooks: dict[HookEvent, list[HookMatcher]] | None = None
|
|
295
|
+
include_partial_messages: bool = False
|
|
296
|
+
fork_session: bool = False
|
|
297
|
+
agents: dict[str, AgentDefinition] | None = None
|
|
298
|
+
setting_sources: list[SettingSource] | None = None
|
|
299
|
+
can_use_tool: CanUseTool | None = None
|
|
300
|
+
"""
|
|
301
|
+
Custom permission handler callback.
|
|
302
|
+
Called when a tool requires permission approval.
|
|
303
|
+
"""
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codebuddy-agent-sdk
|
|
3
|
+
Version: 0.1.16
|
|
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,16 @@
|
|
|
1
|
+
codebuddy_agent_sdk/__init__.py,sha256=MF75KZvSF3PTGk9OwjFEW5R7-vI59lexKn5e9-FY1Dw,2052
|
|
2
|
+
codebuddy_agent_sdk/_binary.py,sha256=7UBOzgooaojNAlb3tFvsN12TBAndcP3YLGD3Ic3LlmI,4302
|
|
3
|
+
codebuddy_agent_sdk/_errors.py,sha256=5ABIym6mazInI33kmt5mR94v6c325jDbi0YCgQjrysY,816
|
|
4
|
+
codebuddy_agent_sdk/_message_parser.py,sha256=U0dy1nqe2kap0_A_VWQN-KME-HEQmDhZQcCbCLVMe4s,3255
|
|
5
|
+
codebuddy_agent_sdk/_version.py,sha256=gd5mG_b7YNb-OjiOR9uFxlVlFC_Qy_2bjDIv8RmlUqM,75
|
|
6
|
+
codebuddy_agent_sdk/client.py,sha256=Bl6l2KFXkSs4j9usuzM7JMYsEO9Np4p6Csg9fR42LtI,10191
|
|
7
|
+
codebuddy_agent_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
codebuddy_agent_sdk/query.py,sha256=LNv4LIdzdg-fRunMlIicu0SAEv5AoAPpu3_w7iDGhYw,9544
|
|
9
|
+
codebuddy_agent_sdk/types.py,sha256=PYCgC6rAElM5VAcDcdDDr4MXCnIXbRcSNwiuTf__Jrk,6926
|
|
10
|
+
codebuddy_agent_sdk/bin/codebuddy,sha256=6dtpXUphR7RK67d96ylaUuKVr_Ez5hWJTw_FgM3bOO8,109791421
|
|
11
|
+
codebuddy_agent_sdk/transport/__init__.py,sha256=zv_8OJHgnWjCInqOiu3GOFby4XVGvDwICHpOsymOlko,166
|
|
12
|
+
codebuddy_agent_sdk/transport/base.py,sha256=ps-4jWU3jL-IiTIL5Pv70zanxdmrknCHZfpxMGBTLoA,626
|
|
13
|
+
codebuddy_agent_sdk/transport/subprocess.py,sha256=m3o-hx2q6U3yeaOPrMxqi6XetsPZdAjjAxBIDiq-vgU,5617
|
|
14
|
+
codebuddy_agent_sdk-0.1.16.dist-info/METADATA,sha256=21FfThYNF_2EmPAa6SEpx6HXeNEaqUcUMDwgyQAyn80,2539
|
|
15
|
+
codebuddy_agent_sdk-0.1.16.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
16
|
+
codebuddy_agent_sdk-0.1.16.dist-info/RECORD,,
|