commandagi 0.5.0__tar.gz → 0.5.1__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.
- {commandagi-0.5.0 → commandagi-0.5.1}/CHANGELOG.md +18 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/PKG-INFO +10 -3
- {commandagi-0.5.0 → commandagi-0.5.1}/README.md +9 -2
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/__init__.py +1 -1
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/client.py +31 -17
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/__init__.py +2 -1
- commandagi-0.5.1/commandagi/design/tsx.py +128 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/kernel.py +6 -6
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_kernel.py +1 -1
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_sdk.py +44 -0
- commandagi-0.5.1/tests/test_tsx.py +58 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/.gitignore +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/LICENSE +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/_generated.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/business.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/cad.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/cadquery.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/documents.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/eda.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/element.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/fab.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/graph.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/ir.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/media.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/monitors.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/office.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/ontology.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/pcb.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/pdf.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/postal.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/records.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/schema.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/schematic.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/solids.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/source.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/standards.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/standards_data.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/tasks.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/threed.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/threed_elements.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/threed_schema.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/twod.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/twod_schema.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/design/workbook_schema.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/gym_env.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi/lerobot.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/commandagi-sdk.schema.json +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/examples/drive_a_sim.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/pyproject.toml +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_business.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_design.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_fab.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_media.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_monitors.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_office.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_ontology.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_pcb.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_pdf.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_postal.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_records.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_schematic.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_source.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_standards.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_tasks.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_threed.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/tests/test_twod.py +0 -0
- {commandagi-0.5.0 → commandagi-0.5.1}/uv.lock +0 -0
|
@@ -4,6 +4,24 @@ One entry for each release. A release is the tag `v<version>` in this repository
|
|
|
4
4
|
TypeScript and Rust SDKs carry the same version number. A version promises nothing about the next one (README
|
|
5
5
|
§ Versions): read this file before you change the version you pin.
|
|
6
6
|
|
|
7
|
+
## 0.5.1 (2026-10-15)
|
|
8
|
+
|
|
9
|
+
Fixed
|
|
10
|
+
|
|
11
|
+
- `Kernel`'s message when no place can run it names the right install: `npm install -g @commandagi/host`, then
|
|
12
|
+
`commandagi threed install`. 0.5.0 said `npm install -g commandagi`, a package with no command.
|
|
13
|
+
- `call()` no longer stops every call after a fixed 120 s. `CommandAGI(timeout=…)` sets how long a call waits (None:
|
|
14
|
+
no limit; default 120 s), and `call(tool, args, timeout=…)` sets it for one call. A call with no answer in time
|
|
15
|
+
raises `CommandAGIError` that says so (`pcb_autoroute: no answer within 120 s`); the platform may still finish the
|
|
16
|
+
operation.
|
|
17
|
+
|
|
18
|
+
Added
|
|
19
|
+
|
|
20
|
+
- `commandagi.design.to_tsx(element)`: a Python document's root element as the TypeScript SDK's code file
|
|
21
|
+
(`export default () => (<group …>…</group>);`), for a place that reads only TSX. It declares the same document as
|
|
22
|
+
the Python (checked on the shipped examples: a 3D part, a schematic, a board, a drawing, a letter, a company, a
|
|
23
|
+
project).
|
|
24
|
+
|
|
7
25
|
## 0.5.0 (2026-10-14)
|
|
8
26
|
|
|
9
27
|
The first release with the design layer. 0.5.0 was prepared on 2026-10-13 and not published; this entry holds all of it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: commandagi
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: The CommandAGI SDK for Python — agent threads, memory and integrations, and live computers, robots and simulated worlds you watch and control.
|
|
5
5
|
Project-URL: Homepage, https://commandagi.com
|
|
6
6
|
Project-URL: Documentation, https://github.com/CommandAGI/commandagi-sdk-python/blob/main/README.md
|
|
@@ -56,6 +56,13 @@ with cagi.launch("simulation/warehouse") as world:
|
|
|
56
56
|
cagi.call("list_snapshots")
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
A call waits 120 s for its answer. `CommandAGI(timeout=600)` sets it for every call (None: no limit), and
|
|
60
|
+
`cagi.call("pcb_autoroute", {...}, timeout=900)` for one call. A call with no answer in time raises
|
|
61
|
+
`CommandAGIError`; the platform may still finish the operation.
|
|
62
|
+
|
|
63
|
+
A Python document can go where only TSX is read: `commandagi.design.to_tsx(result)` writes its root element as the
|
|
64
|
+
TypeScript SDK's code file, which declares the same document.
|
|
65
|
+
|
|
59
66
|
## One surface, generated
|
|
60
67
|
|
|
61
68
|
This SDK, the TypeScript SDK (`npm i commandagi`) and the `commandagi` CLI all come from **one
|
|
@@ -221,7 +228,7 @@ cloud result.
|
|
|
221
228
|
|
|
222
229
|
| place | the kernel | needs |
|
|
223
230
|
| --- | --- | --- |
|
|
224
|
-
| `local` | this computer, offline, no account. `Kernel` starts it and stops it when Python exits; `COMMANDAGI_THREED_URL` names one that runs already (`commandagi threed serve --port 8091`) | Node 22 and, once: `npm install -g commandagi` then `commandagi threed install` (it downloads OpenCascade as WebAssembly, about 130 MB); for a running one, `COMMANDAGI_THREED_TOKEN`, the bearer you started it with |
|
|
231
|
+
| `local` | this computer, offline, no account. `Kernel` starts it and stops it when Python exits; `COMMANDAGI_THREED_URL` names one that runs already (`commandagi threed serve --port 8091`) | Node 22 and, once: `npm install -g @commandagi/host` then `commandagi threed install` (it downloads OpenCascade as WebAssembly, about 130 MB); for a running one, `COMMANDAGI_THREED_TOKEN`, the bearer you started it with |
|
|
225
232
|
| `cloud` | the platform's kernel door (`/kernels/3d/v1/<op>`) | the network and `COMMANDAGI_API_KEY` |
|
|
226
233
|
|
|
227
234
|
A URL in `COMMANDAGI_THREED` is that running service only. Both places speak one contract (`POST <kernel>/v1/<op>`,
|
|
@@ -262,7 +269,7 @@ graph (`run_module(...)["graph"]`) or the graph's JSON text. An entity is `{"bod
|
|
|
262
269
|
## Versions
|
|
263
270
|
|
|
264
271
|
- A release is the tag `v<version>` in this repository and the same version on PyPI. Pin an exact version:
|
|
265
|
-
`commandagi==0.5.
|
|
272
|
+
`commandagi==0.5.1`. A range (`^`, `~=`, `>=`) takes the next release without asking you.
|
|
266
273
|
- The three SDKs (Python, TypeScript, Rust) carry one version number. A vocabulary at version X in one language is
|
|
267
274
|
the vocabulary at version X in the others.
|
|
268
275
|
- A version promises nothing about the next one. CommandAGI keeps no compatibility layers: a release may rename or
|
|
@@ -28,6 +28,13 @@ with cagi.launch("simulation/warehouse") as world:
|
|
|
28
28
|
cagi.call("list_snapshots")
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
A call waits 120 s for its answer. `CommandAGI(timeout=600)` sets it for every call (None: no limit), and
|
|
32
|
+
`cagi.call("pcb_autoroute", {...}, timeout=900)` for one call. A call with no answer in time raises
|
|
33
|
+
`CommandAGIError`; the platform may still finish the operation.
|
|
34
|
+
|
|
35
|
+
A Python document can go where only TSX is read: `commandagi.design.to_tsx(result)` writes its root element as the
|
|
36
|
+
TypeScript SDK's code file, which declares the same document.
|
|
37
|
+
|
|
31
38
|
## One surface, generated
|
|
32
39
|
|
|
33
40
|
This SDK, the TypeScript SDK (`npm i commandagi`) and the `commandagi` CLI all come from **one
|
|
@@ -193,7 +200,7 @@ cloud result.
|
|
|
193
200
|
|
|
194
201
|
| place | the kernel | needs |
|
|
195
202
|
| --- | --- | --- |
|
|
196
|
-
| `local` | this computer, offline, no account. `Kernel` starts it and stops it when Python exits; `COMMANDAGI_THREED_URL` names one that runs already (`commandagi threed serve --port 8091`) | Node 22 and, once: `npm install -g commandagi` then `commandagi threed install` (it downloads OpenCascade as WebAssembly, about 130 MB); for a running one, `COMMANDAGI_THREED_TOKEN`, the bearer you started it with |
|
|
203
|
+
| `local` | this computer, offline, no account. `Kernel` starts it and stops it when Python exits; `COMMANDAGI_THREED_URL` names one that runs already (`commandagi threed serve --port 8091`) | Node 22 and, once: `npm install -g @commandagi/host` then `commandagi threed install` (it downloads OpenCascade as WebAssembly, about 130 MB); for a running one, `COMMANDAGI_THREED_TOKEN`, the bearer you started it with |
|
|
197
204
|
| `cloud` | the platform's kernel door (`/kernels/3d/v1/<op>`) | the network and `COMMANDAGI_API_KEY` |
|
|
198
205
|
|
|
199
206
|
A URL in `COMMANDAGI_THREED` is that running service only. Both places speak one contract (`POST <kernel>/v1/<op>`,
|
|
@@ -234,7 +241,7 @@ graph (`run_module(...)["graph"]`) or the graph's JSON text. An entity is `{"bod
|
|
|
234
241
|
## Versions
|
|
235
242
|
|
|
236
243
|
- A release is the tag `v<version>` in this repository and the same version on PyPI. Pin an exact version:
|
|
237
|
-
`commandagi==0.5.
|
|
244
|
+
`commandagi==0.5.1`. A range (`^`, `~=`, `>=`) takes the next release without asking you.
|
|
238
245
|
- The three SDKs (Python, TypeScript, Rust) carry one version number. A vocabulary at version X in one language is
|
|
239
246
|
the vocabulary at version X in the others.
|
|
240
247
|
- A version promises nothing about the next one. CommandAGI keeps no compatibility layers: a release may rename or
|
|
@@ -49,6 +49,9 @@ class CommandAGIError(Exception):
|
|
|
49
49
|
self.detail = detail
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
_UNSET: Any = object()
|
|
53
|
+
|
|
54
|
+
|
|
52
55
|
class CommandAGI(GeneratedClient):
|
|
53
56
|
"""Client for the CommandAGI platform. One surface for developers and agents alike — an API key's
|
|
54
57
|
scopes are the only difference. ``call(tool, args)`` reaches any platform tool by name."""
|
|
@@ -59,34 +62,45 @@ class CommandAGI(GeneratedClient):
|
|
|
59
62
|
base_url: Optional[str] = None,
|
|
60
63
|
thread_id: Optional[str] = None,
|
|
61
64
|
http: Optional[requests.Session] = None,
|
|
65
|
+
timeout: Optional[float] = 120.0,
|
|
62
66
|
) -> None:
|
|
67
|
+
"""``timeout``: how many seconds a call waits for its answer (None: no limit). A long operation (an autoroute
|
|
68
|
+
of a large board) needs more than the default; ``call(..., timeout=...)`` sets it for one call."""
|
|
63
69
|
self.api_key = api_key or os.environ.get(ENV_API_KEY)
|
|
64
70
|
if not self.api_key:
|
|
65
71
|
raise CommandAGIError("", f"pass api_key or set {ENV_API_KEY}")
|
|
66
72
|
self.base_url = (base_url or os.environ.get(ENV_BASE_URL) or DEFAULT_BASE_URL).rstrip("/")
|
|
67
73
|
self.thread_id = thread_id or os.environ.get(ENV_THREAD_ID) or None
|
|
68
74
|
self._http = http or requests.Session()
|
|
75
|
+
self.timeout = timeout
|
|
69
76
|
self._ids = itertools.count(1)
|
|
70
77
|
self._bind_namespaces()
|
|
71
78
|
|
|
72
79
|
# ── transport ────────────────────────────────────────────────────────────────────────────────
|
|
73
|
-
def call(self, tool: str, args: Optional[Dict[str, Any]] = None) -> Any:
|
|
74
|
-
"""Run ANY platform tool by name — the universal escape hatch. Returns its parsed JSON result.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
def call(self, tool: str, args: Optional[Dict[str, Any]] = None, *, timeout: Any = _UNSET) -> Any:
|
|
81
|
+
"""Run ANY platform tool by name — the universal escape hatch. Returns its parsed JSON result.
|
|
82
|
+
|
|
83
|
+
``timeout`` (seconds, or None for no limit) overrides the client's for this one call. A call with no answer
|
|
84
|
+
in time raises :class:`CommandAGIError`; the platform may still finish the operation."""
|
|
85
|
+
wait = self.timeout if timeout is _UNSET else timeout
|
|
86
|
+
try:
|
|
87
|
+
r = self._http.post(
|
|
88
|
+
self.base_url + "/mcp",
|
|
89
|
+
headers={
|
|
90
|
+
"authorization": f"Bearer {self.api_key}",
|
|
91
|
+
"content-type": "application/json",
|
|
92
|
+
"mcp-protocol-version": "2025-06-18",
|
|
93
|
+
},
|
|
94
|
+
data=json.dumps({
|
|
95
|
+
"jsonrpc": "2.0",
|
|
96
|
+
"id": next(self._ids),
|
|
97
|
+
"method": "tools/call",
|
|
98
|
+
"params": {"name": tool, "arguments": args or {}},
|
|
99
|
+
}),
|
|
100
|
+
timeout=wait,
|
|
101
|
+
)
|
|
102
|
+
except requests.exceptions.Timeout:
|
|
103
|
+
raise CommandAGIError(tool, f"{tool}: no answer within {wait:g} s (pass timeout= to wait longer)")
|
|
90
104
|
try:
|
|
91
105
|
j = r.json()
|
|
92
106
|
except ValueError:
|
|
@@ -29,6 +29,7 @@ from . import cadquery as _cq
|
|
|
29
29
|
from .solids import declare_solids
|
|
30
30
|
from . import source as _source
|
|
31
31
|
from .element import Element, declarer_of
|
|
32
|
+
from .tsx import to_tsx
|
|
32
33
|
# The document vocabularies, one module each (``from commandagi.design.twod import drawing, rect``). Importing them
|
|
33
34
|
# registers what each root element declares.
|
|
34
35
|
from . import business, fab, media, monitors, office, ontology, pcb, pdf, postal, records, schematic, standards, tasks, threed, twod # noqa: F401
|
|
@@ -40,7 +41,7 @@ __all__ = [
|
|
|
40
41
|
"cylinder", "extrude", "fillet", "hole", "instance", "intersect", "linear_pattern", "mirror", "part", "revolve",
|
|
41
42
|
"sketch", "sphere", "subtract", "union",
|
|
42
43
|
"PartRef", "board", "circuit", "component", "connect", "footprints", "net", "part_type_for",
|
|
43
|
-
"Element", "graph_of", "run_module",
|
|
44
|
+
"Element", "graph_of", "run_module", "to_tsx",
|
|
44
45
|
]
|
|
45
46
|
|
|
46
47
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""``to_tsx(element)``: a Python document as the TypeScript SDK's code file, for a place that reads only TSX.
|
|
2
|
+
|
|
3
|
+
The element model is one (``./element.py``): a Python call is a JSX element with the same tag, its attributes by
|
|
4
|
+
their TypeScript names and its children in order. So the TSX is written from the element alone, and it declares the
|
|
5
|
+
same document: ``export default () => (<root …>…</root>);``. The file's extension (``.sch.tsx``, ``.3d.tsx`` …) is the
|
|
6
|
+
caller's to choose, as for a ``.py`` file.
|
|
7
|
+
|
|
8
|
+
What is written: a string attribute as ``name="…"`` (as ``{"…"}`` when it holds a quote, an ``&`` or a line break,
|
|
9
|
+
which JSX would read otherwise); every other value as a JavaScript literal in braces; an attribute that is ``None``
|
|
10
|
+
not at all (the SDKs read an absent attribute and ``undefined`` alike). Texts are written inline with their
|
|
11
|
+
elements, and as ``{"…"}`` when JSX would change them. A value JavaScript has no literal for (NaN, an infinity, an
|
|
12
|
+
object that is not data) is refused by its attribute's name.
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import math
|
|
18
|
+
import re
|
|
19
|
+
from typing import Any, List
|
|
20
|
+
|
|
21
|
+
from .element import Element, _number_text
|
|
22
|
+
|
|
23
|
+
__all__ = ["to_tsx"]
|
|
24
|
+
|
|
25
|
+
_WIDTH = 120
|
|
26
|
+
_IDENT = re.compile(r"^[A-Za-z_$][A-Za-z0-9_$]*$")
|
|
27
|
+
_PLAIN_TEXT = re.compile(r"^[^{}<>&\n\r]*$")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def to_tsx(element: Element, indent: str = " ") -> str:
|
|
31
|
+
"""The TSX code file that declares the same document as ``element`` (the root a ``.py`` document's ``result`` is)."""
|
|
32
|
+
if not isinstance(element, Element):
|
|
33
|
+
raise TypeError(f"to_tsx takes a document's root element (group(...), part(...), board(...) …), not {type(element).__name__}")
|
|
34
|
+
# A capitalised tag (<Company>) is a value in JSX, not an intrinsic element: the file imports it from the SDK.
|
|
35
|
+
named = sorted({t for t in _tags(element) if t[:1].isupper()})
|
|
36
|
+
imports = f'import {{ {", ".join(named)} }} from "commandagi/design";\n\n' if named else ""
|
|
37
|
+
return imports + "export default () => (\n" + "\n".join(_lines(element, 1, indent)) + "\n);\n"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _tags(el: Element) -> List[str]:
|
|
41
|
+
out = [el.tag]
|
|
42
|
+
for c in list(el.children) + list(el.props.values()):
|
|
43
|
+
if isinstance(c, Element):
|
|
44
|
+
out += _tags(c)
|
|
45
|
+
return out
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _js(value: Any, where: str) -> str:
|
|
49
|
+
if value is None:
|
|
50
|
+
return "null"
|
|
51
|
+
if isinstance(value, bool):
|
|
52
|
+
return "true" if value else "false"
|
|
53
|
+
if isinstance(value, (int, float)):
|
|
54
|
+
if isinstance(value, float) and not math.isfinite(value):
|
|
55
|
+
raise ValueError(f"{where}: {value} has no JavaScript literal")
|
|
56
|
+
return _number_text(value)
|
|
57
|
+
if isinstance(value, str):
|
|
58
|
+
return json.dumps(value, ensure_ascii=False)
|
|
59
|
+
if isinstance(value, Element):
|
|
60
|
+
return _inline(value, where)
|
|
61
|
+
if isinstance(value, (list, tuple)):
|
|
62
|
+
return "[" + ", ".join(_js(v, where) for v in value) + "]"
|
|
63
|
+
if isinstance(value, dict):
|
|
64
|
+
if not value:
|
|
65
|
+
return "{}"
|
|
66
|
+
fields = []
|
|
67
|
+
for k, v in value.items():
|
|
68
|
+
if not isinstance(k, str):
|
|
69
|
+
raise ValueError(f"{where}: a key {k!r} is not a string")
|
|
70
|
+
fields.append(f"{k if _IDENT.match(k) else json.dumps(k, ensure_ascii=False)}: {_js(v, where)}")
|
|
71
|
+
return "{ " + ", ".join(fields) + " }"
|
|
72
|
+
raise ValueError(f"{where}: a {type(value).__name__} is not data")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _attr(tag: str, name: str, value: Any) -> str:
|
|
76
|
+
if isinstance(value, str) and not any(c in value for c in '"&\n\r'):
|
|
77
|
+
return f'{name}="{value}"'
|
|
78
|
+
return f"{name}={{{_js(value, f'<{tag}> {name}')}}}"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _attrs(el: Element) -> List[str]:
|
|
82
|
+
return [_attr(el.tag, k, v) for k, v in el.props.items() if v is not None]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _children_inline(el: Element) -> str:
|
|
86
|
+
out = []
|
|
87
|
+
for i, c in enumerate(el.children):
|
|
88
|
+
if isinstance(c, Element):
|
|
89
|
+
out.append(_inline(c, f"<{el.tag}>"))
|
|
90
|
+
else:
|
|
91
|
+
out.append(_inline_text(c, first=i == 0, last=i == len(el.children) - 1))
|
|
92
|
+
return "".join(out)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _inline_text(value: Any, first: bool, last: bool) -> str:
|
|
96
|
+
"""A text between elements on one line: JSX keeps it as written unless it holds a brace, an angle bracket, an
|
|
97
|
+
entity or a line break, or is only spaces at an end (JSX keeps those too, but a reader would not see them)."""
|
|
98
|
+
text = value if isinstance(value, str) else _number_text(value)
|
|
99
|
+
plain = bool(text) and _PLAIN_TEXT.match(text) and not ((first and text[0] == " ") or (last and text[-1] == " "))
|
|
100
|
+
return text if plain else "{" + json.dumps(text, ensure_ascii=False) + "}"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _inline(el: Element, where: str = "") -> str:
|
|
104
|
+
head = " ".join([el.tag] + _attrs(el))
|
|
105
|
+
if not el.children:
|
|
106
|
+
return f"<{head} />"
|
|
107
|
+
return f"<{head}>{_children_inline(el)}</{el.tag}>"
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _lines(el: Element, depth: int, indent: str) -> List[str]:
|
|
111
|
+
pad = indent * depth
|
|
112
|
+
attrs = _attrs(el)
|
|
113
|
+
holds_text = any(not isinstance(c, Element) for c in el.children)
|
|
114
|
+
one = pad + _inline(el) if holds_text or not el.children else None
|
|
115
|
+
if one is not None and len(one) <= _WIDTH:
|
|
116
|
+
return [one]
|
|
117
|
+
head = " ".join([el.tag] + attrs)
|
|
118
|
+
if len(pad) + len(head) + 3 <= _WIDTH:
|
|
119
|
+
opening = [f"{pad}<{head}" + (" />" if not el.children else ">")]
|
|
120
|
+
else:
|
|
121
|
+
opening = [f"{pad}<{el.tag}"] + [pad + indent + a for a in attrs] + [pad + ("/>" if not el.children else ">")]
|
|
122
|
+
if not el.children:
|
|
123
|
+
return opening
|
|
124
|
+
if holds_text:
|
|
125
|
+
body = [pad + indent + _children_inline(el)]
|
|
126
|
+
else:
|
|
127
|
+
body = [line for c in el.children for line in _lines(c, depth + 1, indent)]
|
|
128
|
+
return opening + body + [f"{pad}</{el.tag}>"]
|
|
@@ -21,8 +21,8 @@ file cannot say that two features are missing from it.
|
|
|
21
21
|
where the kernel is not installed is passed over; a refusal of the op itself is the answer and is not asked elsewhere.
|
|
22
22
|
|
|
23
23
|
================= =====================================================================================================
|
|
24
|
-
``local`` this computer, offline, no account. The SDK starts ``commandagi threed serve`` (the
|
|
25
|
-
|
|
24
|
+
``local`` this computer, offline, no account. The SDK starts ``commandagi threed serve`` (the npm package
|
|
25
|
+
``@commandagi/host``: ``npm install -g @commandagi/host`` then ``commandagi threed install``, once) and stops it
|
|
26
26
|
when Python exits. ``COMMANDAGI_THREED_URL`` (with ``COMMANDAGI_THREED_TOKEN``) names one that
|
|
27
27
|
runs already in its place.
|
|
28
28
|
``cloud`` the platform's kernel door, with your ``COMMANDAGI_API_KEY``. Needs the network and an account.
|
|
@@ -209,7 +209,7 @@ class _Local:
|
|
|
209
209
|
if cls.installed is None:
|
|
210
210
|
cli = shutil.which("commandagi")
|
|
211
211
|
if not cli:
|
|
212
|
-
cls.installed = "no `commandagi` command is on PATH (npm install -g commandagi, then commandagi threed install)"
|
|
212
|
+
cls.installed = "no `commandagi` command is on PATH (npm install -g @commandagi/host, then commandagi threed install)"
|
|
213
213
|
else:
|
|
214
214
|
said: Any = None
|
|
215
215
|
try:
|
|
@@ -223,7 +223,7 @@ class _Local:
|
|
|
223
223
|
pass
|
|
224
224
|
if not isinstance(said, dict):
|
|
225
225
|
cls.installed = (f"`{cli} threed status` gave no status (it said: {heard[:200]}); install the local 3D "
|
|
226
|
-
"kernel with `npm install -g commandagi` then `commandagi threed install`")
|
|
226
|
+
"kernel with `npm install -g @commandagi/host` then `commandagi threed install`")
|
|
227
227
|
elif said.get("installed") is not True:
|
|
228
228
|
cls.installed = "the local 3D kernel is not installed (run `commandagi threed install` once)"
|
|
229
229
|
else:
|
|
@@ -238,8 +238,8 @@ class _Local:
|
|
|
238
238
|
cli = shutil.which("commandagi")
|
|
239
239
|
if not cli:
|
|
240
240
|
raise KernelError(
|
|
241
|
-
"the local 3D kernel is the
|
|
242
|
-
"Install it once: `npm install -g commandagi` then `commandagi threed install`"
|
|
241
|
+
"the local 3D kernel is the npm package `@commandagi/host`, and no `commandagi` command is on PATH. "
|
|
242
|
+
"Install it once: `npm install -g @commandagi/host` then `commandagi threed install`"
|
|
243
243
|
)
|
|
244
244
|
# The bearer is made here and lives in this process and the child's environment only.
|
|
245
245
|
token = secrets.token_hex(32)
|
|
@@ -170,7 +170,7 @@ class Placed(unittest.TestCase):
|
|
|
170
170
|
self.assertIn("local: no `commandagi` command is on PATH; cloud: no such place here", str(nowhere.exception))
|
|
171
171
|
|
|
172
172
|
def test_the_local_kernel_is_found_from_what_commandagi_threed_status_prints(self):
|
|
173
|
-
#
|
|
173
|
+
# @commandagi/host's `commandagi threed status` prints one JSON object over several lines (cli.mjs: print).
|
|
174
174
|
folder = tempfile.mkdtemp()
|
|
175
175
|
self.addCleanup(shutil.rmtree, folder)
|
|
176
176
|
cli = os.path.join(folder, "commandagi")
|
|
@@ -135,6 +135,50 @@ class Sessions(unittest.TestCase):
|
|
|
135
135
|
self.assertEqual(http.calls[-1], ("kill_process", {"pid": "thread:th_world"}))
|
|
136
136
|
|
|
137
137
|
|
|
138
|
+
class Timeouts(unittest.TestCase):
|
|
139
|
+
"""A call waits as long as the caller says (feedback #8: a fixed 120 s cut long autoroutes off)."""
|
|
140
|
+
|
|
141
|
+
def setUp(self):
|
|
142
|
+
import http.server
|
|
143
|
+
import threading
|
|
144
|
+
|
|
145
|
+
class Slow(http.server.BaseHTTPRequestHandler):
|
|
146
|
+
def do_POST(self):
|
|
147
|
+
import time
|
|
148
|
+
|
|
149
|
+
self.rfile.read(int(self.headers["content-length"]))
|
|
150
|
+
time.sleep(0.6)
|
|
151
|
+
body = json.dumps({"jsonrpc": "2.0", "id": 1, "result": {"content": [{"type": "text", "text": '{"ok": true}'}]}}).encode()
|
|
152
|
+
self.send_response(200)
|
|
153
|
+
self.send_header("content-type", "application/json")
|
|
154
|
+
self.send_header("content-length", str(len(body)))
|
|
155
|
+
self.end_headers()
|
|
156
|
+
self.wfile.write(body)
|
|
157
|
+
|
|
158
|
+
def log_message(self, *a):
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
self.server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Slow)
|
|
162
|
+
threading.Thread(target=self.server.serve_forever, daemon=True).start()
|
|
163
|
+
self.url = f"http://127.0.0.1:{self.server.server_address[1]}"
|
|
164
|
+
|
|
165
|
+
def tearDown(self):
|
|
166
|
+
self.server.shutdown()
|
|
167
|
+
self.server.server_close()
|
|
168
|
+
|
|
169
|
+
def test_the_clients_timeout_bounds_every_call(self):
|
|
170
|
+
cagi = CommandAGI(api_key="cagi_test", base_url=self.url, timeout=0.2)
|
|
171
|
+
with self.assertRaises(CommandAGIError) as caught:
|
|
172
|
+
cagi.call("pcb_autoroute", {})
|
|
173
|
+
self.assertEqual(caught.exception.tool, "pcb_autoroute")
|
|
174
|
+
self.assertIn("no answer within 0.2 s", str(caught.exception))
|
|
175
|
+
|
|
176
|
+
def test_a_calls_own_timeout_overrides_the_clients(self):
|
|
177
|
+
cagi = CommandAGI(api_key="cagi_test", base_url=self.url, timeout=0.2)
|
|
178
|
+
self.assertEqual(cagi.call("pcb_autoroute", {}, timeout=5), {"ok": True})
|
|
179
|
+
self.assertEqual(CommandAGI(api_key="cagi_test", base_url=self.url, timeout=None).call("whoami"), {"ok": True})
|
|
180
|
+
|
|
181
|
+
|
|
138
182
|
def _snake(name):
|
|
139
183
|
import re
|
|
140
184
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""``to_tsx(element)``: a Python document written as the TypeScript SDK's code file, for a place that reads only TSX
|
|
2
|
+
(feedback #10). That the TSX declares the same document as the Python is checked in the repository, where both run
|
|
3
|
+
(tests/workbench/sdk-python-tsx.test.mjs). Run: python -m unittest tests.test_tsx"""
|
|
4
|
+
import unittest
|
|
5
|
+
|
|
6
|
+
from commandagi.design import to_tsx
|
|
7
|
+
from commandagi.design.office import b, p
|
|
8
|
+
from commandagi.design.pcb import board, component, trace
|
|
9
|
+
from commandagi.design.schematic import group, resistor
|
|
10
|
+
from commandagi.design.threed import extrude, parameter, part
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ToTsx(unittest.TestCase):
|
|
14
|
+
def test_a_document_is_its_default_export(self):
|
|
15
|
+
self.assertEqual(
|
|
16
|
+
to_tsx(group("Divider", resistor("R1", resistance="3k", sch_x=114.3, sch_y=88.9))),
|
|
17
|
+
'export default () => (\n'
|
|
18
|
+
' <group name="Divider">\n'
|
|
19
|
+
' <resistor name="R1" resistance="3k" schX={114.3} schY={88.9} />\n'
|
|
20
|
+
' </group>\n'
|
|
21
|
+
');\n',
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def test_values_are_javascript_literals(self):
|
|
25
|
+
tsx = to_tsx(part(
|
|
26
|
+
parameter(name="t", value=6.0, unit="mm", bindings=[{"target": "e1", "field": "distance"}]),
|
|
27
|
+
extrude(id="e1", profile={"sketch": "s1"}, distance=-2.5, through=True, consumes=None),
|
|
28
|
+
name='The "plate" & co',
|
|
29
|
+
))
|
|
30
|
+
self.assertIn('<part name={"The \\"plate\\" & co"}>', tsx)
|
|
31
|
+
self.assertIn('<parameter name="t" value={6} unit="mm" bindings={[{ target: "e1", field: "distance" }]} />', tsx)
|
|
32
|
+
self.assertIn('<extrude id="e1" profile={{ sketch: "s1" }} distance={-2.5} through={true} />', tsx)
|
|
33
|
+
|
|
34
|
+
def test_a_snake_case_keyword_is_written_by_its_attribute_name(self):
|
|
35
|
+
tsx = to_tsx(board(trace(layer="F.Cu", points=[[9, 22], [9, 10]], from_=".V1 > .pin1", to=".R1 > .pin1"),
|
|
36
|
+
component(name="R1", footprint="smd-0805", pcb_x=10, pcb_y=10), width=40))
|
|
37
|
+
self.assertIn('from=".V1 > .pin1"', tsx)
|
|
38
|
+
self.assertIn('pcbX={10}', tsx)
|
|
39
|
+
self.assertIn('points={[[9, 22], [9, 10]]}', tsx)
|
|
40
|
+
|
|
41
|
+
def test_text_is_inline_and_kept_exactly(self):
|
|
42
|
+
tsx = to_tsx(p("The run ", b("passed"), " {twice} <ok>"))
|
|
43
|
+
self.assertIn('<p>The run <b>passed</b>{" {twice} <ok>"}</p>', tsx)
|
|
44
|
+
|
|
45
|
+
def test_a_long_tag_puts_one_attribute_on_a_line(self):
|
|
46
|
+
tsx = to_tsx(group("G", resistor("R1", resistance="3k", sch_x=114.3, sch_y=88.9, footprint="Resistor_SMD:R_0402_1005Metric_Pad0.72x0.64mm_HandSolder")))
|
|
47
|
+
self.assertIn(' <resistor\n name="R1"\n resistance="3k"\n', tsx)
|
|
48
|
+
self.assertIn(' footprint="Resistor_SMD:R_0402_1005Metric_Pad0.72x0.64mm_HandSolder"\n />\n', tsx)
|
|
49
|
+
|
|
50
|
+
def test_what_javascript_cannot_say_is_refused(self):
|
|
51
|
+
with self.assertRaisesRegex(ValueError, "distance: nan"):
|
|
52
|
+
to_tsx(part(extrude(id="e1", distance=float("nan"))))
|
|
53
|
+
with self.assertRaisesRegex(TypeError, "a document's root element"):
|
|
54
|
+
to_tsx({"nodes": {}})
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|