soit-cli 0.1.0__tar.gz → 1.5.2__tar.gz

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,6 @@
1
+ __pycache__/
2
+ .venv/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ dist/
6
+ *.egg-info/
soit_cli-1.5.2/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 SOIT LLC
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.5
2
+ Name: soit-cli
3
+ Version: 1.5.2
4
+ Summary: Command-line client for SOIT: sign in, run agents, replay regressions, export evidence
5
+ Project-URL: Homepage, https://soit.ai
6
+ Project-URL: Documentation, https://docs.soit.ai
7
+ Project-URL: Repository, https://github.com/soit-ai/soit
8
+ Project-URL: Changelog, https://github.com/soit-ai/soit/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/soit-ai/soit/issues
10
+ Author-email: Jude <jude@soit.ai>
11
+ Maintainer-email: SOIT maintainers <jude@soit.ai>
12
+ License-Expression: Apache-2.0
13
+ License-File: LICENSE
14
+ Keywords: agents,cli,evaluation,evidence,governance,llm,soit
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Intended Audience :: System Administrators
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Software Development
26
+ Classifier: Topic :: Utilities
27
+ Requires-Python: >=3.11
28
+ Requires-Dist: httpx>=0.27
29
+ Requires-Dist: pyyaml>=6
30
+ Description-Content-Type: text/markdown
31
+
32
+ # soit: the SOIT command line
33
+
34
+ A small client for the SOIT API: sign in with an API key, run an agent,
35
+ replay regression sets on a new model, run and manage evaluation datasets,
36
+ and take evidence out.
37
+
38
+ ```bash
39
+ uv tool install soit-cli # or: pipx install soit-cli
40
+ soit login --url https://soit.example.com
41
+ ```
42
+
43
+ The package on PyPI is [`soit-cli`](https://pypi.org/project/soit-cli/);
44
+ the command it installs is `soit`. To run the checkout instead, for example
45
+ to try a change before it is released, install from the repository:
46
+
47
+ ```bash
48
+ uv tool install ./cli # or: pipx install ./cli
49
+ ```
50
+
51
+ `soit login` asks for an API key (create one under **Settings › API**), checks
52
+ it, and stores it with the address in your configuration directory, readable
53
+ by you alone. In CI, set `SOIT_API_URL` and `SOIT_API_KEY` instead; the
54
+ environment wins over the stored file. `SOIT_CONFIG` names another file.
55
+
56
+ | Command | Does |
57
+ | ------- | ---- |
58
+ | `soit login [--url URL] [--api-key KEY \| --api-key-stdin]` | check a key and remember it |
59
+ | `soit whoami` | show who the stored key signs in as |
60
+ | `soit logout` | forget the stored key |
61
+ | `soit run AGENT_ID "message" [--thread ID] [--json]` | run an agent's published version once; the answer on stdout, the run on stderr |
62
+ | `soit eval MODEL_REF [--agent ID]... [--dataset NAME] [--max-cases N] [--json] [--fail-on-regression]` | replay agents' regression sets on a model next to the one they use ([model replays](https://github.com/soit-ai/soit/blob/main/docs/model-replays.md)) |
63
+ | `soit eval run AGENT_ID [--dataset NAME] [--version ID] [--model MODEL_REF] [--max-cases N] [--json] [--fail-on-regression] [--fail-on-failure]` | run one dataset on an agent now (the published version unless `--version`), print each case's result and the report it records ([evaluations](https://github.com/soit-ai/soit/blob/main/docs/evaluations.md)) |
64
+ | `soit dataset list [--agent ID] [--archived] [--json]` | list the workspace's datasets with revision, case count and latest report |
65
+ | `soit dataset export DATASET [--agent ID] [-o FILE]` | write a dataset's cases as JSONL (`DATASET` is its id or name; standard output by default) |
66
+ | `soit dataset import DATASET FILE [--agent ID] [--create] [--note TEXT]` | add the cases of a JSONL file, all or none: a file with any bad line imports nothing and every bad line is listed with its number; `--create --agent ID` creates the dataset first |
67
+ | `soit agent export AGENT_ID [-o FILE]` | write an agent and its published (or current) version's specification as YAML, without ids |
68
+ | `soit agent import FILE [--name NAME]` | create an agent, and its version as a draft, from such a file; the model, tool and knowledge refs it names must exist in the workspace |
69
+ | `soit export evidence RUN_ID [-o FILE]` | save a run's evidence bundle, after checking it against the server's SHA-256 ([ledger](https://github.com/soit-ai/soit/blob/main/docs/ledger.md)) |
70
+ | `soit export runs\|steps\|costs\|audit\|events --since ISO [--until ISO] [--format jsonl\|csv] [-o FILE\|-]` | save one kind of ledger record for a window |
71
+
72
+ Exit codes: `0` success, `1` a refusal or failure, `2` a usage error, `3` an
73
+ `eval --fail-on-regression` that found cases passing on the current model and
74
+ failing on the candidate, so a CI job can stop a model switch:
75
+
76
+ ```bash
77
+ soit eval model:openai:gpt-6 --dataset smoke --fail-on-regression
78
+ ```
79
+
80
+ `soit eval run` exits `3` the same way: with `--fail-on-regression` when a case
81
+ that passed in the report's baseline fails now, and with `--fail-on-failure`
82
+ when any case fails, as the publish gate would. A CI job can keep a dataset
83
+ in the repository and evaluate every change against it:
84
+
85
+ ```bash
86
+ soit dataset import refunds evals/refunds.jsonl --agent agt_123 --create
87
+ soit eval run agt_123 --dataset refunds --fail-on-regression
88
+ ```
@@ -0,0 +1,57 @@
1
+ # soit: the SOIT command line
2
+
3
+ A small client for the SOIT API: sign in with an API key, run an agent,
4
+ replay regression sets on a new model, run and manage evaluation datasets,
5
+ and take evidence out.
6
+
7
+ ```bash
8
+ uv tool install soit-cli # or: pipx install soit-cli
9
+ soit login --url https://soit.example.com
10
+ ```
11
+
12
+ The package on PyPI is [`soit-cli`](https://pypi.org/project/soit-cli/);
13
+ the command it installs is `soit`. To run the checkout instead, for example
14
+ to try a change before it is released, install from the repository:
15
+
16
+ ```bash
17
+ uv tool install ./cli # or: pipx install ./cli
18
+ ```
19
+
20
+ `soit login` asks for an API key (create one under **Settings › API**), checks
21
+ it, and stores it with the address in your configuration directory, readable
22
+ by you alone. In CI, set `SOIT_API_URL` and `SOIT_API_KEY` instead; the
23
+ environment wins over the stored file. `SOIT_CONFIG` names another file.
24
+
25
+ | Command | Does |
26
+ | ------- | ---- |
27
+ | `soit login [--url URL] [--api-key KEY \| --api-key-stdin]` | check a key and remember it |
28
+ | `soit whoami` | show who the stored key signs in as |
29
+ | `soit logout` | forget the stored key |
30
+ | `soit run AGENT_ID "message" [--thread ID] [--json]` | run an agent's published version once; the answer on stdout, the run on stderr |
31
+ | `soit eval MODEL_REF [--agent ID]... [--dataset NAME] [--max-cases N] [--json] [--fail-on-regression]` | replay agents' regression sets on a model next to the one they use ([model replays](https://github.com/soit-ai/soit/blob/main/docs/model-replays.md)) |
32
+ | `soit eval run AGENT_ID [--dataset NAME] [--version ID] [--model MODEL_REF] [--max-cases N] [--json] [--fail-on-regression] [--fail-on-failure]` | run one dataset on an agent now (the published version unless `--version`), print each case's result and the report it records ([evaluations](https://github.com/soit-ai/soit/blob/main/docs/evaluations.md)) |
33
+ | `soit dataset list [--agent ID] [--archived] [--json]` | list the workspace's datasets with revision, case count and latest report |
34
+ | `soit dataset export DATASET [--agent ID] [-o FILE]` | write a dataset's cases as JSONL (`DATASET` is its id or name; standard output by default) |
35
+ | `soit dataset import DATASET FILE [--agent ID] [--create] [--note TEXT]` | add the cases of a JSONL file, all or none: a file with any bad line imports nothing and every bad line is listed with its number; `--create --agent ID` creates the dataset first |
36
+ | `soit agent export AGENT_ID [-o FILE]` | write an agent and its published (or current) version's specification as YAML, without ids |
37
+ | `soit agent import FILE [--name NAME]` | create an agent, and its version as a draft, from such a file; the model, tool and knowledge refs it names must exist in the workspace |
38
+ | `soit export evidence RUN_ID [-o FILE]` | save a run's evidence bundle, after checking it against the server's SHA-256 ([ledger](https://github.com/soit-ai/soit/blob/main/docs/ledger.md)) |
39
+ | `soit export runs\|steps\|costs\|audit\|events --since ISO [--until ISO] [--format jsonl\|csv] [-o FILE\|-]` | save one kind of ledger record for a window |
40
+
41
+ Exit codes: `0` success, `1` a refusal or failure, `2` a usage error, `3` an
42
+ `eval --fail-on-regression` that found cases passing on the current model and
43
+ failing on the candidate, so a CI job can stop a model switch:
44
+
45
+ ```bash
46
+ soit eval model:openai:gpt-6 --dataset smoke --fail-on-regression
47
+ ```
48
+
49
+ `soit eval run` exits `3` the same way: with `--fail-on-regression` when a case
50
+ that passed in the report's baseline fails now, and with `--fail-on-failure`
51
+ when any case fails, as the publish gate would. A CI job can keep a dataset
52
+ in the repository and evaluate every change against it:
53
+
54
+ ```bash
55
+ soit dataset import refunds evals/refunds.jsonl --agent agt_123 --create
56
+ soit eval run agt_123 --dataset refunds --fail-on-regression
57
+ ```
@@ -0,0 +1,64 @@
1
+ [project]
2
+ name = "soit-cli"
3
+ version = "1.5.2"
4
+ description = "Command-line client for SOIT: sign in, run agents, replay regressions, export evidence"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ authors = [
9
+ { name = "Jude", email = "jude@soit.ai" }
10
+ ]
11
+ maintainers = [
12
+ { name = "SOIT maintainers", email = "jude@soit.ai" }
13
+ ]
14
+ requires-python = ">=3.11"
15
+ keywords = ["soit", "cli", "agents", "llm", "governance", "evaluation", "evidence"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Environment :: Console",
19
+ "Intended Audience :: Developers",
20
+ "Intended Audience :: System Administrators",
21
+ "Operating System :: OS Independent",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3 :: Only",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Topic :: Software Development",
28
+ "Topic :: Utilities",
29
+ ]
30
+ dependencies = ["httpx>=0.27", "pyyaml>=6"]
31
+
32
+ [project.urls]
33
+ Homepage = "https://soit.ai"
34
+ Documentation = "https://docs.soit.ai"
35
+ Repository = "https://github.com/soit-ai/soit"
36
+ Changelog = "https://github.com/soit-ai/soit/blob/main/CHANGELOG.md"
37
+ Issues = "https://github.com/soit-ai/soit/issues"
38
+
39
+ [project.scripts]
40
+ soit = "soit_cli.main:main"
41
+
42
+ [dependency-groups]
43
+ dev = ["pytest>=8", "ruff>=0.6"]
44
+
45
+ [build-system]
46
+ requires = ["hatchling>=1.27"]
47
+ build-backend = "hatchling.build"
48
+
49
+ [tool.hatch.build.targets.sdist]
50
+ include = ["soit_cli", "tests", "LICENSE", "README.md", "pyproject.toml"]
51
+
52
+ [tool.hatch.build.targets.wheel]
53
+ packages = ["soit_cli"]
54
+
55
+ [tool.pytest.ini_options]
56
+ pythonpath = ["."]
57
+ testpaths = ["tests"]
58
+
59
+ [tool.ruff]
60
+ target-version = "py311"
61
+ line-length = 120
62
+
63
+ [tool.ruff.lint]
64
+ select = ["E", "W", "F", "I", "B", "C4", "UP", "ARG001"]
@@ -0,0 +1,3 @@
1
+ """Command-line client for SOIT."""
2
+
3
+ __version__ = "1.5.2"
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from soit_cli.main import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,199 @@
1
+ """A thin client for the parts of the SOIT API the CLI uses."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import re
7
+ from typing import Any
8
+
9
+ import httpx
10
+
11
+ from soit_cli import __version__
12
+ from soit_cli.config import Credentials
13
+
14
+ DEFAULT_TIMEOUT = 60.0
15
+ RUN_TIMEOUT = 600.0
16
+ REPLAY_TIMEOUT = 3600.0
17
+ EXPORT_TIMEOUT = 600.0
18
+
19
+
20
+ class SoitError(Exception):
21
+ """A refusal from SOIT, or a failure to reach it."""
22
+
23
+ def __init__(
24
+ self,
25
+ message: str,
26
+ *,
27
+ status: int | None = None,
28
+ code: str | None = None,
29
+ details: dict[str, Any] | None = None,
30
+ ) -> None:
31
+ super().__init__(message)
32
+ self.status = status
33
+ self.code = code
34
+ self.details = details or {}
35
+
36
+ def __str__(self) -> str:
37
+ return f"{self.code}: {self.args[0]}" if self.code else str(self.args[0])
38
+
39
+
40
+ def _filename(disposition: str | None, fallback: str) -> str:
41
+ match = re.search(r'filename="?([^";]+)"?', disposition or "")
42
+ return match.group(1) if match else fallback
43
+
44
+
45
+ class SoitClient:
46
+ """One signed-in connection to a SOIT API."""
47
+
48
+ def __init__(self, credentials: Credentials, *, transport: httpx.BaseTransport | None = None) -> None:
49
+ headers = {
50
+ "Authorization": f"Bearer {credentials.api_key}",
51
+ "User-Agent": f"soit-cli/{__version__}",
52
+ }
53
+ if credentials.workspace_id:
54
+ headers["X-Workspace-Id"] = credentials.workspace_id
55
+ self.url = credentials.url
56
+ self.http = httpx.Client(
57
+ base_url=credentials.url,
58
+ headers=headers,
59
+ timeout=DEFAULT_TIMEOUT,
60
+ transport=transport,
61
+ )
62
+
63
+ def close(self) -> None:
64
+ self.http.close()
65
+
66
+ def _send(self, method: str, path: str, **kwargs: Any) -> httpx.Response:
67
+ try:
68
+ response = self.http.request(method, path, **kwargs)
69
+ except httpx.TimeoutException as exc:
70
+ raise SoitError(f"{self.url} did not answer in time") from exc
71
+ except httpx.HTTPError as exc:
72
+ raise SoitError(f"cannot reach {self.url}: {exc}") from exc
73
+ if response.is_success:
74
+ return response
75
+ try:
76
+ body = response.json()
77
+ except ValueError:
78
+ body = {}
79
+ details: dict[str, Any] = {}
80
+ if isinstance(body, dict):
81
+ code = body.get("code")
82
+ message = body.get("message") or response.reason_phrase
83
+ if isinstance(body.get("details"), dict):
84
+ details = body["details"]
85
+ else:
86
+ code, message = None, response.reason_phrase
87
+ raise SoitError(str(message), status=response.status_code, code=str(code) if code else None, details=details)
88
+
89
+ def _data(self, method: str, path: str, **kwargs: Any) -> Any:
90
+ body = self._send(method, path, **kwargs).json()
91
+ # SOIT's own API wraps answers as {"success": true, "data": ...}.
92
+ if isinstance(body, dict) and body.get("success") is True and "data" in body:
93
+ return body["data"]
94
+ return body
95
+
96
+ def me(self) -> dict[str, Any]:
97
+ return self._data("GET", "/api/v1/me")
98
+
99
+ def tools(self) -> list[dict[str, Any]]:
100
+ return self._data("GET", "/api/v1/tools")
101
+
102
+ def run_agent(self, agent_id: str, text: str, *, thread_id: str | None = None) -> dict[str, Any]:
103
+ body: dict[str, Any] = {"input": text}
104
+ if thread_id:
105
+ body["thread_id"] = thread_id
106
+ return self._data("POST", f"/api/v1/agents/{agent_id}/execute", json=body, timeout=RUN_TIMEOUT)
107
+
108
+ def model_replay(
109
+ self,
110
+ model_ref: str,
111
+ *,
112
+ agent_ids: list[str] | None = None,
113
+ dataset: str | None = None,
114
+ max_cases: int | None = None,
115
+ ) -> dict[str, Any]:
116
+ body: dict[str, Any] = {"model_ref": model_ref}
117
+ if agent_ids:
118
+ body["agent_ids"] = agent_ids
119
+ if dataset:
120
+ body["dataset"] = dataset
121
+ if max_cases is not None:
122
+ body["max_cases"] = max_cases
123
+ return self._data("POST", "/api/v1/evaluations/model-replays", json=body, timeout=REPLAY_TIMEOUT)
124
+
125
+ def list_datasets(self, *, agent_id: str | None = None, archived: bool = False) -> list[dict[str, Any]]:
126
+ params: dict[str, Any] = {"status": "archived" if archived else "active", "limit": 200}
127
+ if agent_id:
128
+ params["subject_id"] = agent_id
129
+ return self._data("GET", "/api/v1/evaluations/datasets", params=params)
130
+
131
+ def create_dataset(self, agent_id: str, name: str, *, description: str = "") -> dict[str, Any]:
132
+ body = {"subject_id": agent_id, "name": name, "description": description}
133
+ return self._data("POST", "/api/v1/evaluations/datasets", json=body)
134
+
135
+ def export_dataset(self, dataset_id: str) -> str:
136
+ """The dataset's cases as JSONL, in the format import reads."""
137
+
138
+ response = self._send("GET", f"/api/v1/evaluations/datasets/{dataset_id}/export", timeout=EXPORT_TIMEOUT)
139
+ return response.content.decode("utf-8")
140
+
141
+ def import_dataset(self, dataset_id: str, content: str, *, note: str = "") -> dict[str, Any]:
142
+ """Add every case of a JSONL text, or none of them if any line is wrong."""
143
+
144
+ body = {"content": content, "note": note}
145
+ return self._data("POST", f"/api/v1/evaluations/datasets/{dataset_id}/import", json=body)
146
+
147
+ def run_evaluation(
148
+ self,
149
+ agent_id: str,
150
+ *,
151
+ dataset: str,
152
+ version_id: str | None = None,
153
+ model_ref: str | None = None,
154
+ max_cases: int | None = None,
155
+ ) -> dict[str, Any]:
156
+ """Run a dataset on an agent version and answer with the report it records."""
157
+
158
+ body: dict[str, Any] = {"subject_id": agent_id, "dataset": dataset}
159
+ if version_id:
160
+ body["subject_version_id"] = version_id
161
+ if model_ref:
162
+ body["model_ref"] = model_ref
163
+ if max_cases is not None:
164
+ body["max_cases"] = max_cases
165
+ return self._data("POST", "/api/v1/evaluations/run", json=body, timeout=REPLAY_TIMEOUT)
166
+
167
+ def export_agent(self, agent_id: str) -> dict[str, Any]:
168
+ """The agent as a file: its fields and its published or current version's specification."""
169
+
170
+ return self._data("GET", f"/api/v1/agents/{agent_id}/export")
171
+
172
+ def import_agent(self, document: dict[str, Any]) -> dict[str, Any]:
173
+ """A new agent, and its draft version, from an agent file."""
174
+
175
+ return self._data("POST", "/api/v1/agents/import", json=document)
176
+
177
+ def evidence(self, run_id: str) -> tuple[str, bytes, str]:
178
+ """A run's evidence bundle: file name, bytes, and its checked digest."""
179
+
180
+ response = self._send("GET", f"/api/v1/runs/{run_id}/evidence", timeout=EXPORT_TIMEOUT)
181
+ content = response.content
182
+ digest = hashlib.sha256(content).hexdigest()
183
+ announced = response.headers.get("x-soit-evidence-sha256")
184
+ if announced and announced.lower() != digest:
185
+ raise SoitError(f"the evidence bundle does not match its digest ({announced} announced, {digest} received)")
186
+ return _filename(response.headers.get("content-disposition"), f"soit-evidence-{run_id}.zip"), content, digest
187
+
188
+ def export(self, kind: str, *, since: str, until: str | None, fmt: str) -> tuple[str, bytes, str | None]:
189
+ """One kind of ledger record in a window: file name, bytes, contract version."""
190
+
191
+ params = {"since": since, "format": fmt}
192
+ if until:
193
+ params["until"] = until
194
+ response = self._send("GET", f"/api/v1/exports/{kind}", params=params, timeout=EXPORT_TIMEOUT)
195
+ return (
196
+ _filename(response.headers.get("content-disposition"), f"soit-{kind}.{fmt}"),
197
+ response.content,
198
+ response.headers.get("x-soit-ledger-schema"),
199
+ )