deliberaide-cli 0.1.5__tar.gz → 0.1.6__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.
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/PKG-INFO +1 -1
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/copilot_chat.py +145 -27
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli.egg-info/PKG-INFO +1 -1
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/setup.py +1 -1
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/README.md +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/__init__.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/__main__.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/core/__init__.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/core/manifest.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/core/session.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/deliberaide_cli.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/route_manifest.json +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/utils/__init__.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/utils/api_backend.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/utils/formatting.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli/utils/repl_skin.py +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli.egg-info/SOURCES.txt +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli.egg-info/dependency_links.txt +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli.egg-info/entry_points.txt +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli.egg-info/requires.txt +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli.egg-info/top_level.txt +0 -0
- {deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/setup.cfg +0 -0
|
@@ -122,12 +122,19 @@ class ChatResult:
|
|
|
122
122
|
frame_counts: dict[str, int] = field(default_factory=dict)
|
|
123
123
|
duration_seconds: float = 0.0
|
|
124
124
|
timed_out: bool = False
|
|
125
|
+
over_budget: bool = False # the printing budget passed; the turn may still have finished during the hold
|
|
125
126
|
|
|
126
127
|
@property
|
|
127
128
|
def ok(self) -> bool:
|
|
128
129
|
return self.final is not None and self.error is None and not self.timed_out
|
|
129
130
|
|
|
130
131
|
|
|
132
|
+
# The server keeps a turn alive for this long after its client disconnects; a client that
|
|
133
|
+
# reconnects within the window re-attaches (see synthesis/cli_briefing_reattach_2026-09-08.md).
|
|
134
|
+
SERVER_DISCONNECT_GRACE_SECONDS = 45.0
|
|
135
|
+
DEFAULT_HOLD_SECONDS = 900.0
|
|
136
|
+
|
|
137
|
+
|
|
131
138
|
def copilot_message_frame(
|
|
132
139
|
*,
|
|
133
140
|
text: str,
|
|
@@ -161,22 +168,40 @@ def run_chat_turn(
|
|
|
161
168
|
timeout_seconds: float,
|
|
162
169
|
ping_interval: float,
|
|
163
170
|
on_frame: Callable[[dict[str, Any]], None] | None = None,
|
|
171
|
+
hold_seconds: float = 0.0,
|
|
172
|
+
on_budget: Callable[[ChatResult], None] | None = None,
|
|
164
173
|
) -> ChatResult:
|
|
165
174
|
"""Send one frame and consume server frames until the turn ends.
|
|
166
175
|
|
|
167
176
|
``websocket`` needs ``send(str)`` and ``recv(timeout=float)`` (websockets.sync); a
|
|
168
177
|
``TimeoutError`` from ``recv`` means silence, which is answered with a ``ping`` like
|
|
169
178
|
the web client's heartbeat. The turn ends on ``copilot_done``, ``error``,
|
|
170
|
-
``quota_exceeded
|
|
179
|
+
``quota_exceeded`` or connection close.
|
|
180
|
+
|
|
181
|
+
``timeout_seconds`` is the printing budget. When it passes and ``hold_seconds`` is
|
|
182
|
+
positive, the socket stays open quietly (no ``on_frame`` calls) for up to
|
|
183
|
+
``hold_seconds`` more, because the server discards a turn whose client goes away;
|
|
184
|
+
``on_budget`` is called once at that moment. With ``hold_seconds`` 0 the call returns
|
|
185
|
+
at the budget with ``timed_out`` set, as it did before.
|
|
171
186
|
"""
|
|
172
187
|
started = time.monotonic()
|
|
173
188
|
deadline = started + timeout_seconds
|
|
189
|
+
hard_deadline = deadline + max(hold_seconds, 0.0)
|
|
174
190
|
result = ChatResult(conversation_id=conversation_id)
|
|
175
191
|
websocket.send(json_dumps(frame, compact=True))
|
|
192
|
+
quiet = False
|
|
176
193
|
|
|
177
194
|
while True:
|
|
178
|
-
|
|
195
|
+
now = time.monotonic()
|
|
196
|
+
remaining = (hard_deadline if quiet else deadline) - now
|
|
179
197
|
if remaining <= 0:
|
|
198
|
+
if not quiet and hold_seconds > 0:
|
|
199
|
+
quiet = True
|
|
200
|
+
result.over_budget = True
|
|
201
|
+
if on_budget is not None:
|
|
202
|
+
on_budget(result)
|
|
203
|
+
continue
|
|
204
|
+
result.over_budget = True
|
|
180
205
|
result.timed_out = True
|
|
181
206
|
break
|
|
182
207
|
try:
|
|
@@ -199,7 +224,7 @@ def run_chat_turn(
|
|
|
199
224
|
data = event.get("data") if isinstance(event.get("data"), dict) else {}
|
|
200
225
|
result.frames += 1
|
|
201
226
|
result.frame_counts[frame_type] = result.frame_counts.get(frame_type, 0) + 1
|
|
202
|
-
if on_frame is not None:
|
|
227
|
+
if on_frame is not None and not quiet:
|
|
203
228
|
on_frame(event)
|
|
204
229
|
|
|
205
230
|
if frame_type == "copilot_conversation_created" and data.get("conversation_id"):
|
|
@@ -218,6 +243,34 @@ def run_chat_turn(
|
|
|
218
243
|
return result
|
|
219
244
|
|
|
220
245
|
|
|
246
|
+
def keep_socket_alive(websocket: Any, seconds: float, *, ping_interval: float = 30.0) -> str:
|
|
247
|
+
"""Hold a bare Co-Pilot socket for ``seconds`` so a detached turn stays re-attached.
|
|
248
|
+
|
|
249
|
+
Answers silence with pings like ``run_chat_turn``. Returns ``"terminal"`` as soon as a
|
|
250
|
+
``copilot_done``/``copilot_response_final``/``error`` frame arrives (the caller should
|
|
251
|
+
poll the messages endpoint right away), ``"closed"`` if the server closed the socket,
|
|
252
|
+
otherwise ``"elapsed"``.
|
|
253
|
+
"""
|
|
254
|
+
end = time.monotonic() + max(seconds, 0.0)
|
|
255
|
+
while True:
|
|
256
|
+
remaining = end - time.monotonic()
|
|
257
|
+
if remaining <= 0:
|
|
258
|
+
return "elapsed"
|
|
259
|
+
try:
|
|
260
|
+
raw = websocket.recv(timeout=min(ping_interval, remaining))
|
|
261
|
+
except TimeoutError:
|
|
262
|
+
websocket.send(json_dumps({"type": "ping", "data": {}}, compact=True))
|
|
263
|
+
continue
|
|
264
|
+
except ConnectionClosed:
|
|
265
|
+
return "closed"
|
|
266
|
+
try:
|
|
267
|
+
event = json.loads(raw)
|
|
268
|
+
except (TypeError, ValueError):
|
|
269
|
+
continue
|
|
270
|
+
if isinstance(event, dict) and str(event.get("type") or "") in ("copilot_done", "copilot_response_final", "error", "quota_exceeded"):
|
|
271
|
+
return "terminal"
|
|
272
|
+
|
|
273
|
+
|
|
221
274
|
# ------------------------------------------------------------------ wait (HTTP)
|
|
222
275
|
|
|
223
276
|
|
|
@@ -339,7 +392,14 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
339
392
|
@click.option("--web-search/--no-web-search", default=None, help="web_search_enabled; omitted unless given.")
|
|
340
393
|
@click.option("--hide-from-chat", is_flag=True, help="Run the turn without a visible user message (show_in_chat=false).")
|
|
341
394
|
@click.option("--x-organisation-id", default=None, help="Organisation header; falls back to the profile default.")
|
|
342
|
-
@click.option("--timeout-seconds", type=float, default=900.0, show_default=True,
|
|
395
|
+
@click.option("--timeout-seconds", type=float, default=900.0, show_default=True,
|
|
396
|
+
help="Budget for streaming the turn. After it the connection is held quietly (see --hold-seconds) "
|
|
397
|
+
"because the server drops a turn whose client goes away.")
|
|
398
|
+
@click.option("--hold-seconds", type=float, default=DEFAULT_HOLD_SECONDS, show_default=True,
|
|
399
|
+
help="How long to keep the connection open after the budget so the server can finish; 0 returns at the budget.")
|
|
400
|
+
@click.option("--detach", is_flag=True,
|
|
401
|
+
help=f"Return at the budget and leave the turn on the server; run `copilot wait --conversation-id <id>` "
|
|
402
|
+
f"within {SERVER_DISCONNECT_GRACE_SECONDS:.0f} s or the server cancels it. Same as --hold-seconds 0.")
|
|
343
403
|
@click.option("--ping-interval", type=float, default=30.0, show_default=True, help="Heartbeat while the server is silent.")
|
|
344
404
|
@click.option("--stream/--no-stream", default=True, show_default=True, help="Print server frames as they arrive (NDJSON in --json mode).")
|
|
345
405
|
@click.option("--dry-run", is_flag=True, help="Print the frame that would be sent and exit.")
|
|
@@ -358,11 +418,15 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
358
418
|
hide_from_chat: bool,
|
|
359
419
|
x_organisation_id: str | None,
|
|
360
420
|
timeout_seconds: float,
|
|
421
|
+
hold_seconds: float,
|
|
422
|
+
detach: bool,
|
|
361
423
|
ping_interval: float,
|
|
362
424
|
stream: bool,
|
|
363
425
|
dry_run: bool,
|
|
364
426
|
) -> None:
|
|
365
427
|
"""Send one Co-Pilot message over the WebSocket, exactly like the web app, and stream the turn."""
|
|
428
|
+
if detach:
|
|
429
|
+
hold_seconds = 0.0
|
|
366
430
|
org_headers = _org_header(runtime, x_organisation_id)
|
|
367
431
|
scope: dict[str, Any] = {"discussion_ids": list(discussion_ids), "discussion_id": None, "project_id": project_id,
|
|
368
432
|
"selected_workflow": None, "workspace_state": {}}
|
|
@@ -405,6 +469,22 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
405
469
|
else:
|
|
406
470
|
_human_frame_printer(click.echo)(event)
|
|
407
471
|
|
|
472
|
+
def on_budget(partial: ChatResult) -> None:
|
|
473
|
+
notice = {
|
|
474
|
+
"notice": "budget_reached",
|
|
475
|
+
"conversation_id": partial.conversation_id,
|
|
476
|
+
"still_running": True,
|
|
477
|
+
"holding_seconds": hold_seconds,
|
|
478
|
+
}
|
|
479
|
+
if runtime.json_output:
|
|
480
|
+
click.echo(json_dumps(notice, compact=True))
|
|
481
|
+
click.echo(
|
|
482
|
+
f"Budget of {timeout_seconds:.0f} s reached; the turn is still running on the server. "
|
|
483
|
+
f"Holding the connection quietly for up to {hold_seconds:.0f} s (frames are no longer printed).",
|
|
484
|
+
err=True,
|
|
485
|
+
)
|
|
486
|
+
click.echo(f"conversation id: {partial.conversation_id or '?'}", err=True)
|
|
487
|
+
|
|
408
488
|
with websocket_connect(url, additional_headers=headers, open_timeout=runtime.profile.timeout_seconds) as websocket:
|
|
409
489
|
result = run_chat_turn(
|
|
410
490
|
websocket,
|
|
@@ -413,6 +493,8 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
413
493
|
timeout_seconds=timeout_seconds,
|
|
414
494
|
ping_interval=ping_interval,
|
|
415
495
|
on_frame=on_frame,
|
|
496
|
+
hold_seconds=hold_seconds,
|
|
497
|
+
on_budget=on_budget,
|
|
416
498
|
)
|
|
417
499
|
|
|
418
500
|
envelope = {
|
|
@@ -424,6 +506,8 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
424
506
|
"message": result.final,
|
|
425
507
|
"error": result.error,
|
|
426
508
|
"timed_out": result.timed_out,
|
|
509
|
+
"over_budget": result.over_budget,
|
|
510
|
+
"still_running": result.timed_out and result.error is None,
|
|
427
511
|
"frames": result.frames,
|
|
428
512
|
"frame_counts": result.frame_counts,
|
|
429
513
|
"duration_seconds": result.duration_seconds,
|
|
@@ -434,9 +518,16 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
434
518
|
elif not stream:
|
|
435
519
|
click.echo(str((result.final or {}).get("content") or ""))
|
|
436
520
|
if not result.ok:
|
|
437
|
-
if
|
|
438
|
-
|
|
439
|
-
|
|
521
|
+
if result.timed_out and result.error is None:
|
|
522
|
+
click.echo(
|
|
523
|
+
f"Co-Pilot turn did not finish within the budget; it is still running on the server, which cancels it "
|
|
524
|
+
f"{SERVER_DISCONNECT_GRACE_SECONDS:.0f} s after the last client goes away. Run now:",
|
|
525
|
+
err=True,
|
|
526
|
+
)
|
|
527
|
+
click.echo(f" deliberaide-cli --profile {runtime.profile.name} copilot wait --conversation-id {result.conversation_id or '<id>'}", err=True)
|
|
528
|
+
click.echo(str(result.conversation_id or ""), err=True)
|
|
529
|
+
elif not runtime.json_output:
|
|
530
|
+
click.echo(f"Co-Pilot turn did not finish: {json_dumps(result.error or {}, compact=True)}", err=True)
|
|
440
531
|
raise SystemExit(1)
|
|
441
532
|
|
|
442
533
|
@click.command("wait")
|
|
@@ -445,6 +536,9 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
445
536
|
@click.option("--x-organisation-id", default=None)
|
|
446
537
|
@click.option("--timeout-seconds", type=float, default=900.0, show_default=True)
|
|
447
538
|
@click.option("--interval", type=float, default=15.0, show_default=True)
|
|
539
|
+
@click.option("--socket/--no-socket", default=True, show_default=True,
|
|
540
|
+
help="Open a bare Co-Pilot WebSocket first and hold it while polling, so a turn whose `chat` client "
|
|
541
|
+
"went away is re-attached instead of cancelled (must start within 45 s of the disconnect).")
|
|
448
542
|
@click.pass_obj
|
|
449
543
|
def copilot_wait(
|
|
450
544
|
runtime: Any,
|
|
@@ -453,30 +547,54 @@ def install_copilot_commands(root: click.Group) -> None:
|
|
|
453
547
|
x_organisation_id: str | None,
|
|
454
548
|
timeout_seconds: float,
|
|
455
549
|
interval: float,
|
|
550
|
+
socket: bool,
|
|
456
551
|
) -> None:
|
|
457
|
-
"""
|
|
552
|
+
"""Wait for a turn's final answer: re-attach to the server over the WebSocket and poll the persisted messages."""
|
|
458
553
|
headers = _org_header(runtime, x_organisation_id)
|
|
554
|
+
websocket = None
|
|
555
|
+
if socket:
|
|
556
|
+
ws_headers = {**_cookie_header(runtime), **headers}
|
|
557
|
+
if "Cookie" not in ws_headers:
|
|
558
|
+
raise click.ClickException("No session cookies for this profile. Run `deliberaide-cli auth login` first.")
|
|
559
|
+
url = runtime.backend.build_websocket_url(WS_PATH)
|
|
560
|
+
try:
|
|
561
|
+
websocket = websocket_connect(url, additional_headers=ws_headers, open_timeout=runtime.profile.timeout_seconds)
|
|
562
|
+
except Exception as exc: # noqa: BLE001 - polling still works without the re-attach
|
|
563
|
+
click.echo(f"could not open the Co-Pilot socket ({exc}); polling without re-attaching", err=True)
|
|
459
564
|
deadline = time.monotonic() + timeout_seconds
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
if
|
|
475
|
-
|
|
565
|
+
try:
|
|
566
|
+
while True:
|
|
567
|
+
response = runtime.backend.request(
|
|
568
|
+
"GET", f"/api/v1/copilot/conversations/{conversation_id}/messages", params={"limit": 200}, headers=headers
|
|
569
|
+
)
|
|
570
|
+
if not response.is_success:
|
|
571
|
+
raise click.ClickException(f"GET messages failed: HTTP {response.status_code} {response.text[:200]}")
|
|
572
|
+
body = response.json()
|
|
573
|
+
messages = body if isinstance(body, list) else (body.get("items") or body.get("messages") or [])
|
|
574
|
+
message = select_terminal_message(messages, after=after)
|
|
575
|
+
if message is not None:
|
|
576
|
+
envelope = {"ok": True, "operation": "copilot.wait", "response": {"conversation_id": conversation_id, "message": message}}
|
|
577
|
+
click.echo(json_dumps(envelope, compact=True) if runtime.json_output else str(message.get("content") or ""))
|
|
578
|
+
return
|
|
579
|
+
if time.monotonic() >= deadline:
|
|
580
|
+
if runtime.json_output:
|
|
581
|
+
click.echo(json_dumps({"ok": False, "operation": "copilot.wait", "response": {"conversation_id": conversation_id, "message": None, "timed_out": True}}, compact=True))
|
|
582
|
+
else:
|
|
583
|
+
click.echo("No terminal assistant message yet.", err=True)
|
|
584
|
+
raise SystemExit(1)
|
|
585
|
+
if websocket is not None:
|
|
586
|
+
outcome = keep_socket_alive(websocket, interval)
|
|
587
|
+
if outcome == "closed":
|
|
588
|
+
click.echo("Co-Pilot socket closed by the server; polling continues without it", err=True)
|
|
589
|
+
websocket = None
|
|
476
590
|
else:
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
591
|
+
time.sleep(interval)
|
|
592
|
+
finally:
|
|
593
|
+
if websocket is not None:
|
|
594
|
+
try:
|
|
595
|
+
websocket.close()
|
|
596
|
+
except Exception: # noqa: BLE001
|
|
597
|
+
pass
|
|
480
598
|
|
|
481
599
|
group.add_command(copilot_chat)
|
|
482
600
|
group.add_command(copilot_wait)
|
|
@@ -7,7 +7,7 @@ LONG_DESCRIPTION = (Path(__file__).parent / "deliberaide_cli" / "README.md").rea
|
|
|
7
7
|
|
|
8
8
|
setup(
|
|
9
9
|
name="deliberaide-cli",
|
|
10
|
-
version="0.1.
|
|
10
|
+
version="0.1.6",
|
|
11
11
|
description="Stateful, agent-native CLI for the deliberAIde v2 API",
|
|
12
12
|
long_description=LONG_DESCRIPTION,
|
|
13
13
|
long_description_content_type="text/markdown",
|
|
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
|
{deliberaide_cli-0.1.5 → deliberaide_cli-0.1.6}/deliberaide_cli.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|