minimax-code-sdk 0.1.0__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.
- minimax_code/__init__.py +66 -0
- minimax_code/_args.py +90 -0
- minimax_code/_cli.py +205 -0
- minimax_code/_items.py +71 -0
- minimax_code/_protocol.py +56 -0
- minimax_code/client.py +76 -0
- minimax_code/errors.py +167 -0
- minimax_code/py.typed +0 -0
- minimax_code/sync.py +71 -0
- minimax_code/thread.py +480 -0
- minimax_code/types.py +192 -0
- minimax_code_sdk-0.1.0.dist-info/METADATA +174 -0
- minimax_code_sdk-0.1.0.dist-info/RECORD +15 -0
- minimax_code_sdk-0.1.0.dist-info/WHEEL +4 -0
- minimax_code_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: minimax-code-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for driving the local MiniMax Code (mcode) agent.
|
|
5
|
+
Project-URL: Homepage, https://agent.minimax.io
|
|
6
|
+
Project-URL: Repository, https://github.com/MiniMax-AI/minimax-code
|
|
7
|
+
Project-URL: Issues, https://github.com/MiniMax-AI/minimax-code/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agent,coding-agent,mcode,minimax,minimax-code,sdk
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: typing-extensions>=4.7
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# minimax-code-sdk
|
|
25
|
+
|
|
26
|
+
Python SDK for driving the local [MiniMax Code](https://agent.minimax.io) agent (`mcode`).
|
|
27
|
+
|
|
28
|
+
It mirrors the TypeScript SDK
|
|
29
|
+
[`@minimax-ai/code-sdk`](https://github.com/MiniMax-AI/minimax-code/tree/main/packages/code-sdk): every Turn runs
|
|
30
|
+
`mcode exec --output-format=stream-json` and continues the Session with `--session`.
|
|
31
|
+
|
|
32
|
+
## Requirements
|
|
33
|
+
|
|
34
|
+
- Python 3.10+
|
|
35
|
+
- The `mcode` CLI (0.6.3 or newer): `npm install -g @minimax-ai/code`
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install minimax-code-sdk # or: uv add minimax-code-sdk
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Import it as `minimax_code`.
|
|
44
|
+
|
|
45
|
+
The CLI is found from `MCodeOptions(bin=...)`, then the `MCODE_BIN` environment variable,
|
|
46
|
+
then `PATH`. The SDK never starts it through a shell. On Windows, the `mcode.cmd` launcher
|
|
47
|
+
written by the official installer or by npm / pnpm is followed to the JS entry and Node runtime
|
|
48
|
+
it runs (the installer's release pointer is read again before every Turn, so a CLI self-update
|
|
49
|
+
is picked up); an unrecognized `.cmd` file is rejected, and you can pass the JS entry as `bin`.
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import asyncio
|
|
55
|
+
from minimax_code import MCode, ThreadOptions
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def main() -> None:
|
|
59
|
+
client = MCode()
|
|
60
|
+
thread = client.start_thread(ThreadOptions(cwd=".", permission="smart"))
|
|
61
|
+
|
|
62
|
+
turn = await thread.run("Summarize this repository in one sentence.")
|
|
63
|
+
print(turn.final_response, turn.usage)
|
|
64
|
+
|
|
65
|
+
# Same Session, next Turn.
|
|
66
|
+
turn = await thread.run("Now list its top-level directories.")
|
|
67
|
+
|
|
68
|
+
# Persist thread.id and continue later, in the same workspace.
|
|
69
|
+
later = client.resume_thread(thread.id, ThreadOptions(cwd="."))
|
|
70
|
+
print((await later.run("What did I ask first?")).final_response)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
asyncio.run(main())
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Resuming a Session
|
|
77
|
+
|
|
78
|
+
A Session belongs to the workspace it was created in. Pass the same `cwd` to `resume_thread()`;
|
|
79
|
+
when `cwd` is omitted, the current working directory at that call is used. A Thread pins its
|
|
80
|
+
`cwd` when it is created, so a later `os.chdir()` does not affect it. A different workspace fails with
|
|
81
|
+
`MCodeRunError` ("Session ... belongs to workspace ..."), and retrying does not help.
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
thread = client.start_thread(ThreadOptions(cwd="/path/to/project"))
|
|
85
|
+
await thread.run("...")
|
|
86
|
+
later = client.resume_thread(thread.id, ThreadOptions(cwd="/path/to/project"))
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Streaming
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
streamed = await thread.run_streamed("Fix the failing test.")
|
|
93
|
+
async for event in streamed:
|
|
94
|
+
if event["type"] == "item.updated" and event["item"]["type"] == "agent_message":
|
|
95
|
+
print(event["item"].get("contentDelta", ""), end="")
|
|
96
|
+
elif event["type"] == "turn.failed":
|
|
97
|
+
print("failed:", event.get("error"))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Events are the CLI's stream-json events, passed through unchanged (unknown types included),
|
|
101
|
+
with one exception: an `item.updated` snapshot (no `contentDelta`) identical to the previous
|
|
102
|
+
snapshot of the same item is skipped. Text deltas are never skipped. `turn.failed` is an ordinary
|
|
103
|
+
event; iteration raises only for process or protocol failures.
|
|
104
|
+
|
|
105
|
+
### Cancellation
|
|
106
|
+
|
|
107
|
+
- `streamed.cancel()` sends SIGTERM, the CLI's cancel signal; the stream ends with the CLI's
|
|
108
|
+
final events. SIGTERM is used instead of SIGINT because Ctrl+C in a terminal already sends
|
|
109
|
+
SIGINT to the CLI, and a second SIGINT would skip its graceful shutdown.
|
|
110
|
+
- Leaving the `async for` early (`break` or an exception in the loop body), or cancelling the
|
|
111
|
+
task running `thread.run()`, stops the CLI: SIGTERM, then SIGKILL if it is still running after
|
|
112
|
+
the CLI's 60 second shutdown budget. The next Turn on the same Thread waits for that shutdown
|
|
113
|
+
instead of raising `ThreadBusyError`; `async with streamed:` or `await streamed.aclose()`
|
|
114
|
+
stops it deterministically. On Windows, cancellation stops the CLI immediately.
|
|
115
|
+
- `RunOptions(timeout_ms=...)` is enforced by the CLI. If the CLI is still running 90 seconds
|
|
116
|
+
after `timeout_ms` (its shutdown budget plus startup time), the SDK kills it and raises
|
|
117
|
+
`MCodeRunError` with `status="timeout"`.
|
|
118
|
+
- `exec.completed` ends the Turn. A CLI that keeps running afterwards is stopped after 5 seconds,
|
|
119
|
+
and a background process that inherited the CLI's output does not keep the Turn open.
|
|
120
|
+
|
|
121
|
+
### Blocking API
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from minimax_code import SyncMCode
|
|
125
|
+
|
|
126
|
+
with SyncMCode() as client:
|
|
127
|
+
thread = client.start_thread()
|
|
128
|
+
print(thread.run("hello").final_response)
|
|
129
|
+
for event in thread.run_streamed("again"):
|
|
130
|
+
print(event["type"])
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The blocking API runs its own event loop, so it cannot be used where a loop is already running,
|
|
134
|
+
such as a Jupyter notebook or an `async def` function. Use the async API with `await` there.
|
|
135
|
+
|
|
136
|
+
## Options
|
|
137
|
+
|
|
138
|
+
| Object | Fields |
|
|
139
|
+
| --- | --- |
|
|
140
|
+
| `MCodeOptions` | `bin`, `data_dir` (`MINIMAX_DATA_DIR`), `env` (replaces `os.environ`; values hidden in `repr()`), `config_path` |
|
|
141
|
+
| `ThreadOptions` | `cwd`, `model` (`provider/model`), `effort`, `permission` (`smart`/`full`/`off`), `mode`, `prompt_mode`, `system_prompt`, `append_system_prompt` |
|
|
142
|
+
| `RunOptions` | `files`, `timeout_ms`, `max_steps` |
|
|
143
|
+
|
|
144
|
+
## Errors
|
|
145
|
+
|
|
146
|
+
All errors subclass `MCodeError` (with `exit_code`, `stderr`, `session_id`, `result`, `items`):
|
|
147
|
+
`MCodeNotFoundError`, `MCodeVersionError`, `MCodeInvocationError`, `MCodeRunError`
|
|
148
|
+
(`status`, `category`), `MCodeAbortError`, `MCodeProtocolError`, `ThreadBusyError`.
|
|
149
|
+
Errors can be pickled, for example to return them from a `ProcessPoolExecutor` worker.
|
|
150
|
+
|
|
151
|
+
## Limitations
|
|
152
|
+
|
|
153
|
+
Each Turn is a separate process, so interactive permission prompts (`permission="ask"`) and
|
|
154
|
+
custom in-process tools are not supported yet. A long-lived ACP transport is planned.
|
|
155
|
+
|
|
156
|
+
## Development
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
uv sync
|
|
160
|
+
uv run pytest
|
|
161
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
End-to-end tests against a real CLI and model are opt-in:
|
|
165
|
+
`MCODE_SDK_E2E=1 MCODE_BIN=/path/to/mcode uv run pytest -m e2e`.
|
|
166
|
+
|
|
167
|
+
Release notes are in
|
|
168
|
+
[CHANGELOG.md](https://github.com/MiniMax-AI/minimax-code/blob/main/packages/code-sdk-python/CHANGELOG.md);
|
|
169
|
+
maintainers publish with
|
|
170
|
+
[RELEASING.md](https://github.com/MiniMax-AI/minimax-code/blob/main/packages/code-sdk-python/RELEASING.md).
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
minimax_code/__init__.py,sha256=ndw_xXZBk6RP7hN7u55NiZbEDVZtGV0Pr93byjxNXus,1273
|
|
2
|
+
minimax_code/_args.py,sha256=23WFCz0y3SRqisEChPPsCWvAtl_U3Jzc1kGCcTQh1SE,3251
|
|
3
|
+
minimax_code/_cli.py,sha256=RsmTnNhsMPFDUzF2DZzllKepuP8vR0Ot9Fwy8RMps0o,8818
|
|
4
|
+
minimax_code/_items.py,sha256=rFtcUV2ZstKYiY1x6R0x5dpqflZZDqngMBRdr7UHLgE,2423
|
|
5
|
+
minimax_code/_protocol.py,sha256=rhHZdoTTPDI3QFme5Jg1PoWa15GhI8pvC6QANj7DFP8,2138
|
|
6
|
+
minimax_code/client.py,sha256=yfJuklKml9_lSuzGFfd8aTEmfFzIm0oAOsYOwCkiWSg,3315
|
|
7
|
+
minimax_code/errors.py,sha256=6GUaSgFY8yPeppL7pRWJfo0-Q7oT_OsmxeRGAvs6x4E,5559
|
|
8
|
+
minimax_code/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
minimax_code/sync.py,sha256=t30ejqNP9fDEdLKJLUPes_scFV1vHdGvVdSdFV6MTSQ,2721
|
|
10
|
+
minimax_code/thread.py,sha256=Dr1fIWUp2kdrIrRUx8GUq4u6ngFjsyQ6dF_pOLrG5dM,19271
|
|
11
|
+
minimax_code/types.py,sha256=yiBCPCqjlNRhlhHqKbX-0m2a1cBGVQgpAtJP3blbBt0,5750
|
|
12
|
+
minimax_code_sdk-0.1.0.dist-info/METADATA,sha256=ySYmnyo035RDaxInf4Mb8bF_fwiy3OfKwu3eOWbLGm8,7005
|
|
13
|
+
minimax_code_sdk-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
14
|
+
minimax_code_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=KLtcKUh0L5-NJ-2EiChE0J3_B8td9k8gcph16FgqGOo,1069
|
|
15
|
+
minimax_code_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MiniMax Code
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|