deliberaide-cli 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.
@@ -0,0 +1 @@
1
+ """Utility helpers for deliberaide-cli."""
@@ -0,0 +1,138 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+ from typing import Any
6
+ from urllib.parse import urlencode, urljoin, urlparse, urlunparse
7
+
8
+ import httpx
9
+
10
+ from deliberaide_cli.core.session import CookieRecord
11
+
12
+
13
+ @dataclass(slots=True)
14
+ class DecodedResponse:
15
+ kind: str
16
+ content_type: str | None
17
+ value: Any
18
+ filename: str | None = None
19
+
20
+
21
+ class ApiBackend:
22
+ def __init__(
23
+ self,
24
+ base_url: str,
25
+ timeout_seconds: float,
26
+ cookies: list[CookieRecord] | None = None,
27
+ ) -> None:
28
+ self.client = httpx.Client(
29
+ base_url=base_url,
30
+ timeout=timeout_seconds,
31
+ follow_redirects=True,
32
+ )
33
+ for cookie in cookies or []:
34
+ self.client.cookies.set(
35
+ cookie.name,
36
+ cookie.value,
37
+ domain=cookie.domain,
38
+ path=cookie.path,
39
+ )
40
+
41
+ def export_cookies(self) -> list[CookieRecord]:
42
+ records: list[CookieRecord] = []
43
+ for cookie in self.client.cookies.jar:
44
+ records.append(
45
+ CookieRecord(
46
+ name=cookie.name,
47
+ value=cookie.value,
48
+ domain=cookie.domain or "",
49
+ path=cookie.path or "/",
50
+ secure=bool(cookie.secure),
51
+ expires=cookie.expires,
52
+ )
53
+ )
54
+ return records
55
+
56
+ def request(
57
+ self,
58
+ method: str,
59
+ path: str,
60
+ *,
61
+ params: dict[str, Any] | None = None,
62
+ headers: dict[str, str] | None = None,
63
+ json_body: Any = None,
64
+ data: dict[str, Any] | None = None,
65
+ uploads: list[tuple[str, Path]] | None = None,
66
+ allow_refresh: bool = True,
67
+ ) -> httpx.Response:
68
+ file_handles = []
69
+ files = []
70
+ try:
71
+ for field_name, file_path in uploads or []:
72
+ handle = open(file_path, "rb")
73
+ file_handles.append(handle)
74
+ files.append((field_name, (file_path.name, handle, "application/octet-stream")))
75
+ response = self.client.request(
76
+ method,
77
+ path,
78
+ params=params,
79
+ headers=headers,
80
+ json=json_body,
81
+ data=data,
82
+ files=files or None,
83
+ )
84
+ if response.status_code == 401 and allow_refresh and path != "/api/v1/auth/refresh":
85
+ if any(cookie.name.endswith("refresh") or "refresh" in cookie.name for cookie in self.export_cookies()):
86
+ refresh_response = self.client.post("/api/v1/auth/refresh")
87
+ if refresh_response.is_success:
88
+ response = self.client.request(
89
+ method,
90
+ path,
91
+ params=params,
92
+ headers=headers,
93
+ json=json_body,
94
+ data=data,
95
+ files=files or None,
96
+ )
97
+ return response
98
+ finally:
99
+ for handle in file_handles:
100
+ handle.close()
101
+
102
+ def build_websocket_url(self, path: str, query: dict[str, Any] | None = None) -> str:
103
+ base = urlparse(str(self.client.base_url))
104
+ scheme = "wss" if base.scheme == "https" else "ws"
105
+ url = urljoin(str(self.client.base_url), path.lstrip("/"))
106
+ parsed = urlparse(url)
107
+ params = {key: value for key, value in (query or {}).items() if value is not None}
108
+ return urlunparse(
109
+ (
110
+ scheme,
111
+ parsed.netloc,
112
+ parsed.path,
113
+ "",
114
+ urlencode(params),
115
+ "",
116
+ )
117
+ )
118
+
119
+
120
+ def decode_response(response: httpx.Response) -> DecodedResponse:
121
+ content_type = response.headers.get("content-type", "").split(";", 1)[0].strip() or None
122
+ if content_type and "json" in content_type:
123
+ return DecodedResponse(kind="json", content_type=content_type, value=response.json())
124
+ if content_type and (content_type.startswith("text/") or content_type in {"application/xml", "application/javascript"}):
125
+ return DecodedResponse(kind="text", content_type=content_type, value=response.text)
126
+ if not content_type:
127
+ try:
128
+ return DecodedResponse(kind="json", content_type=None, value=response.json())
129
+ except Exception:
130
+ return DecodedResponse(kind="text", content_type=None, value=response.text)
131
+ filename = None
132
+ disposition = response.headers.get("content-disposition", "")
133
+ for part in disposition.split(";"):
134
+ part = part.strip()
135
+ if part.startswith("filename="):
136
+ filename = part.split("=", 1)[1].strip('"')
137
+ break
138
+ return DecodedResponse(kind="binary", content_type=content_type, value=response.content, filename=filename)
@@ -0,0 +1,86 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+
8
+ def parse_assignment(raw_value: str) -> tuple[str, str]:
9
+ if "=" not in raw_value:
10
+ raise ValueError(f"Expected KEY=VALUE, got: {raw_value}")
11
+ key, value = raw_value.split("=", 1)
12
+ key = key.strip()
13
+ if not key:
14
+ raise ValueError(f"Expected KEY=VALUE, got: {raw_value}")
15
+ return key, value
16
+
17
+
18
+ def load_json_file(path: Path) -> Any:
19
+ return json.loads(path.read_text(encoding="utf-8"))
20
+
21
+
22
+ def load_text_file(path: Path) -> str:
23
+ return path.read_text(encoding="utf-8")
24
+
25
+
26
+ def parse_json_text(raw_value: str) -> Any:
27
+ return json.loads(raw_value)
28
+
29
+
30
+ def coerce_value(raw_value: str, schema: dict[str, Any] | None) -> Any:
31
+ schema = schema or {}
32
+ field_type = schema.get("type")
33
+
34
+ if field_type == "boolean":
35
+ lowered = raw_value.strip().lower()
36
+ if lowered in {"1", "true", "yes", "on"}:
37
+ return True
38
+ if lowered in {"0", "false", "no", "off"}:
39
+ return False
40
+ raise ValueError(f"Expected a boolean value, got: {raw_value}")
41
+
42
+ if field_type == "integer":
43
+ return int(raw_value)
44
+
45
+ if field_type == "number":
46
+ return float(raw_value)
47
+
48
+ if field_type in {"array", "object"}:
49
+ return json.loads(raw_value)
50
+
51
+ return raw_value
52
+
53
+
54
+ def json_dumps(payload: Any, compact: bool = False) -> str:
55
+ if compact:
56
+ return json.dumps(payload, separators=(",", ":"), ensure_ascii=True)
57
+ return json.dumps(payload, indent=2, ensure_ascii=True)
58
+
59
+
60
+ def schema_template(schema: dict[str, Any]) -> Any:
61
+ schema_type = schema.get("type")
62
+ if schema_type == "object" or schema.get("properties"):
63
+ template: dict[str, Any] = {}
64
+ for key, value in schema.get("properties", {}).items():
65
+ template[key] = schema_template(value)
66
+ return template
67
+ if schema_type == "array":
68
+ return [schema_template(schema.get("items", {}))]
69
+ if "enum" in schema:
70
+ return schema["enum"][0]
71
+ if schema_type == "boolean":
72
+ return False
73
+ if schema_type == "integer":
74
+ return 0
75
+ if schema_type == "number":
76
+ return 0.0
77
+ if schema.get("format") == "binary":
78
+ return "<path-to-file>"
79
+ return ""
80
+
81
+
82
+ def pretty_lines(rows: list[tuple[str, str]]) -> str:
83
+ if not rows:
84
+ return ""
85
+ width = max(len(key) for key, _ in rows)
86
+ return "\n".join(f"{key.ljust(width)} {value}" for key, value in rows)
@@ -0,0 +1,44 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ import click
6
+ from prompt_toolkit import PromptSession
7
+ from prompt_toolkit.formatted_text import HTML
8
+ from prompt_toolkit.history import FileHistory
9
+
10
+
11
+ class ReplSkin:
12
+ def __init__(self, app_name: str, version: str, history_path: Path) -> None:
13
+ self.app_name = app_name
14
+ self.version = version
15
+ self.history_path = history_path
16
+ self.history_path.parent.mkdir(parents=True, exist_ok=True)
17
+
18
+ def print_banner(self) -> None:
19
+ click.echo(f"{self.app_name} {self.version}")
20
+ click.echo("Interactive mode. Type 'help' to list commands or 'exit' to leave.")
21
+
22
+ def print_goodbye(self) -> None:
23
+ click.echo("Session closed.")
24
+
25
+ def create_prompt_session(self) -> PromptSession[str]:
26
+ return PromptSession(history=FileHistory(str(self.history_path)))
27
+
28
+ def get_input(self, session: PromptSession[str], profile_name: str, base_url: str) -> str:
29
+ prompt = HTML(
30
+ f"<ansicyan>{self.app_name}</ansicyan> "
31
+ f"<ansigreen>{profile_name}</ansigreen> "
32
+ f"<ansiyellow>{base_url}</ansiyellow> "
33
+ "<ansiblue>&gt;</ansiblue> "
34
+ )
35
+ return session.prompt(prompt)
36
+
37
+ def success(self, message: str) -> None:
38
+ click.echo(message)
39
+
40
+ def error(self, message: str) -> None:
41
+ click.secho(message, fg="red", err=True)
42
+
43
+ def info(self, message: str) -> None:
44
+ click.echo(message)
@@ -0,0 +1,159 @@
1
+ Metadata-Version: 2.4
2
+ Name: deliberaide-cli
3
+ Version: 0.1.0
4
+ Summary: Stateful, agent-native CLI for the deliberAIde v2 API
5
+ Home-page: https://deliberaide.com
6
+ Author: deliberAIde
7
+ Author-email: hello@deliberaide.com
8
+ License: Proprietary
9
+ Project-URL: Homepage, https://deliberaide.com
10
+ Project-URL: Platform, https://platform.deliberaide.com
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: Other/Proprietary License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ Requires-Dist: click>=8.1.7
23
+ Requires-Dist: httpx>=0.28.1
24
+ Requires-Dist: prompt-toolkit>=3.0.48
25
+ Requires-Dist: websockets>=12.0
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: license
33
+ Dynamic: project-url
34
+ Dynamic: requires-dist
35
+ Dynamic: requires-python
36
+ Dynamic: summary
37
+
38
+ # deliberaide-cli
39
+
40
+ `deliberaide-cli` is a stateful command-line harness for the DeliberAIde v2 API.
41
+ It wraps the running FastAPI server over HTTP and WebSockets, keeps a saved profile,
42
+ and exposes every discovered route through generated command groups.
43
+
44
+ ## What it supports
45
+
46
+ - One-shot commands for the current HTTP route surface
47
+ - One-shot commands for the current WebSocket route surface
48
+ - Interactive shell mode when you run `deliberaide-cli` with no subcommand
49
+ - Browser-based CLI sign-in through the DeliberAIde web app
50
+ - Saved base URLs, cookies, and default IDs per profile
51
+ - Machine-readable output with `--json`
52
+ - Binary downloads with `--download`
53
+
54
+ ## Install
55
+
56
+ From the repository root:
57
+
58
+ ```powershell
59
+ python -m pip install -e .\agent-harness
60
+ ```
61
+
62
+ If you prefer a project virtual environment, run the same command with that Python executable instead.
63
+
64
+ ## Basic usage
65
+
66
+ ```powershell
67
+ deliberaide-cli --help
68
+ deliberaide-cli routes list
69
+ deliberaide-cli auth login
70
+ deliberaide-cli users get-current-user-info
71
+ deliberaide-cli context set org_id 11111111-1111-1111-1111-111111111111
72
+ deliberaide-cli projects create-project --name "Pilot workspace"
73
+ ```
74
+
75
+ ## Sign in from the browser
76
+
77
+ By default, `auth login` starts a CLI approval session, opens your browser, and waits for approval:
78
+
79
+ ```powershell
80
+ deliberaide-cli --base-url http://127.0.0.1:8000 auth login
81
+ ```
82
+
83
+ If the browser does not open automatically, copy the URL printed in the terminal into any browser on the same machine.
84
+ After you sign in and approve the request, the CLI saves the returned cookies in your active profile.
85
+
86
+ You can still fall back to direct credentials when needed:
87
+
88
+ ```powershell
89
+ deliberaide-cli --base-url http://127.0.0.1:8000 auth login --email you@example.com --password secret
90
+ ```
91
+
92
+ ## JSON request bodies
93
+
94
+ Use direct field flags for simple object bodies:
95
+
96
+ ```powershell
97
+ deliberaide-cli projects create-project --name "Pilot workspace" --description "CLI-created"
98
+ ```
99
+
100
+ Use raw JSON for richer payloads:
101
+
102
+ ```powershell
103
+ deliberaide-cli projects create-project --body '{"name":"Pilot workspace","target_language":"en"}'
104
+ ```
105
+
106
+ Or load JSON from a file:
107
+
108
+ ```powershell
109
+ deliberaide-cli projects create-project --body-file .\payload.json
110
+ ```
111
+
112
+ ## Multipart uploads
113
+
114
+ ```powershell
115
+ deliberaide-cli upload upload-audio --file .\meeting.mp3 --discussion-id 22222222-2222-2222-2222-222222222222 --config '{"language":"en"}'
116
+ ```
117
+
118
+ ```powershell
119
+ deliberaide-cli upload upload-bulk --files .\a.wav --files .\b.wav --session-id 33333333-3333-3333-3333-333333333333
120
+ ```
121
+
122
+ ## Binary responses
123
+
124
+ ```powershell
125
+ deliberaide-cli qr get-session-qr-codes-zip --session-id 44444444-4444-4444-4444-444444444444 --download .\session-qr.zip
126
+ ```
127
+
128
+ ## Profiles and saved defaults
129
+
130
+ ```powershell
131
+ deliberaide-cli profile show
132
+ deliberaide-cli profile set-base-url http://127.0.0.1:8000
133
+ deliberaide-cli context set discussion_id 55555555-5555-5555-5555-555555555555
134
+ deliberaide-cli context show
135
+ deliberaide-cli context undo
136
+ ```
137
+
138
+ ## Interactive shell
139
+
140
+ Run with no subcommand to enter the shell:
141
+
142
+ ```powershell
143
+ deliberaide-cli
144
+ ```
145
+
146
+ Inside the shell, enter the same commands you would run normally, for example:
147
+
148
+ ```text
149
+ routes list
150
+ auth login
151
+ users get-current-user-info
152
+ exit
153
+ ```
154
+
155
+ ## Tests
156
+
157
+ ```powershell
158
+ python -m pytest .\agent-harness\deliberaide_cli\tests -v
159
+ ```
@@ -0,0 +1,17 @@
1
+ deliberaide_cli/README.md,sha256=Yqtn1ipTyd7Dlu5OQGeBO8OvquFV5tPSoldJhZKLUHI,3312
2
+ deliberaide_cli/__init__.py,sha256=PVu3vZfJo74RvRYNRCr-zc2nwZQZlMZEnl4Gr_Ax4Y8,50
3
+ deliberaide_cli/__main__.py,sha256=h_rx1m5EFZIpnEmlC32msAJFEtuoDkHXJzxZZ7sPB4k,90
4
+ deliberaide_cli/deliberaide_cli.py,sha256=myG-hk-HdxXA5kNm-pkShCSTf2w2o-qSsOMTPWeN5Y0,37078
5
+ deliberaide_cli/route_manifest.json,sha256=ieCGTTa1XFje4h2xHvRF9HZrdqQUkVhjSJKhci0z2m8,1218277
6
+ deliberaide_cli/core/__init__.py,sha256=4Y0nZPz_iGZRBquyd04QLLu2XWMl_c83tP8V9eofxX4,41
7
+ deliberaide_cli/core/manifest.py,sha256=VWo4A7iyhs6npNo-P9K0H5WhuE8c8dcwDNnLGTk2W1w,5377
8
+ deliberaide_cli/core/session.py,sha256=qQld5HkeF3NuYcRebD7RHEmJ3C9TQWUCakkPQlZ17Cs,4650
9
+ deliberaide_cli/utils/__init__.py,sha256=WWJPEzkP3xtWtYDM-7m47I6r_dShEoQ1pDhZP2Nl-ok,44
10
+ deliberaide_cli/utils/api_backend.py,sha256=lfN5eA2DiW3HDs7q0N0B7mvZyjN5kAZKpQKL5479rmc,5115
11
+ deliberaide_cli/utils/formatting.py,sha256=tTHL58MLtxkAMWRuVWDHygtjQuqtHH8vR1S1kRuT7Mc,2487
12
+ deliberaide_cli/utils/repl_skin.py,sha256=ZViw5VsDKjznemDvKe9MN-Eyq8jN8_2-URqtteZepEg,1478
13
+ deliberaide_cli-0.1.0.dist-info/METADATA,sha256=D1VqhxapbjZW354bP_tV4cKTcXG7sLo5pNfpT5kjoXw,4676
14
+ deliberaide_cli-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
15
+ deliberaide_cli-0.1.0.dist-info/entry_points.txt,sha256=NSbUd8zZuMQ7E9vAlSPxg_oNrb8VXMVNqZKEXGgrZVM,73
16
+ deliberaide_cli-0.1.0.dist-info/top_level.txt,sha256=qE9yJpnr9WfU11HRl4vEtPVtlcyy-kuMmBT5R0OMnJ4,16
17
+ deliberaide_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ deliberaide-cli = deliberaide_cli.deliberaide_cli:main
@@ -0,0 +1 @@
1
+ deliberaide_cli