delos-cli 5.9.22__tar.gz → 5.9.30__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.
- {delos_cli-5.9.22 → delos_cli-5.9.30}/PKG-INFO +1 -1
- delos_cli-5.9.30/delos_cli/_build.json +5 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/transport/chats.py +130 -6
- delos_cli-5.9.30/delos_cli/transport/conversation_rows.py +71 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/pyproject.toml +1 -1
- delos_cli-5.9.22/delos_cli/_build.json +0 -5
- {delos_cli-5.9.22 → delos_cli-5.9.30}/.gitignore +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/README.md +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/__main__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/agent/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/agent/session.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/agent/tools.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/agent/transport.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/agent/turn.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/base.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/chat/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/chat/app.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/chat/commands.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/chat/render.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/chat/rewind.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/apps/replay.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/auth/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/auth/config.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/auth/mfa.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/auth/oauth.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/auth/token_manager.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/checkpoints.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/commands/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/commands/base.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/commands/builtin.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/commands/mcp.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/commands/permissions.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/commands/prompts.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/commands/sandbox.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/context_report.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ctx.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/file_state.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/git_context.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/hooks.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/loop.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/main.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/client.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/config.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/handlers.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/landing.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/manager.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/remote.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/mcp/state.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/permissions.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/project_context.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/public_key.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/approval.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/bwrap.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/config.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/core.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/denial.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/platform.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/policy.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/seatbelt.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/seatbelt.sbpl +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sandbox/seatbelt_network.sbpl +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/sentry_identity.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/serve/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/serve/app.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/serve/confirm.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/serve/protocol.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/serve/rpc.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/serve/server.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/settings.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/skills.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/state.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/telemetry.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tool_output.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/ask_user_input.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/edit_content.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/explore.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/glob_tool.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/grep.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/read.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/run_shell.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/task.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/todo_write.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/verify.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/tools/write_content.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/transport/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/transport/client.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/transport/documents.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/transport/integrations.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/transport/models.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/banner.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/chat_picker.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/collapse.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/completer.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/lexer.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/model_picker.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/output.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/repl.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/ui/style.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/delos_cli/usage_report.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/agent/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/agent/test_hooks.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/agent/test_steering.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/conftest.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/context/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/context/test_checkpoints.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/context/test_permissions.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/context/test_project_context.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/context/test_skills.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/mcp/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/mcp/fake_server.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/mcp/test_client.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/mcp/test_manager.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/mcp/test_remote.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_approval.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_bwrap.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_config.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_denial.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_integration.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_platform.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_policy.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/sandbox/test_seatbelt.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/serve/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/serve/test_confirm.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/serve/test_steer.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/tools/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/tools/test_file_state.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/tools/test_run_shell.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/tools/test_tool_output.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/ui/__init__.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/ui/test_steering_keys.py +0 -0
- {delos_cli-5.9.22 → delos_cli-5.9.30}/tests/ui/test_transcript_view.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: delos-cli
|
|
3
|
-
Version: 5.9.
|
|
3
|
+
Version: 5.9.30
|
|
4
4
|
Summary: Terminal REPL for the Delos agent — the Claude-Code-style CLI for Delos.
|
|
5
5
|
Project-URL: Homepage, https://delos.so
|
|
6
6
|
Project-URL: Repository, https://github.com/Delos-Intelligence/cosmos-saas
|
|
@@ -24,6 +24,7 @@ from urllib.parse import urlencode
|
|
|
24
24
|
from delos_cli import __version__ as _cli_version
|
|
25
25
|
|
|
26
26
|
from .client import HTTP_ERROR_THRESHOLD, TransportError
|
|
27
|
+
from .conversation_rows import rows_to_messages, text_of
|
|
27
28
|
|
|
28
29
|
if TYPE_CHECKING:
|
|
29
30
|
from .client import AuthedClient
|
|
@@ -77,8 +78,49 @@ async def list_recent(
|
|
|
77
78
|
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
78
79
|
msg = f"HTTP {resp.status_code}: {resp.text[:400]}"
|
|
79
80
|
raise TransportError(msg)
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
items = [_row_to_item(r) for r in resp.json()]
|
|
82
|
+
items += await _list_conversations(http, org_uuid, folder=folder, limit=limit)
|
|
83
|
+
items.sort(key=lambda item: item.updated_at, reverse=True)
|
|
84
|
+
return items[:limit]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
async def _list_conversations(
|
|
88
|
+
http: AuthedClient,
|
|
89
|
+
org_uuid: str,
|
|
90
|
+
*,
|
|
91
|
+
folder: str | None,
|
|
92
|
+
limit: int,
|
|
93
|
+
) -> list[ChatListItem]:
|
|
94
|
+
"""The signed-in user's unified ``conversations`` of the CLI, titled by their Drive node."""
|
|
95
|
+
params = {
|
|
96
|
+
"select": "id,message_count,last_message_at",
|
|
97
|
+
"org_id": f"eq.{org_uuid}",
|
|
98
|
+
"app": "eq.cli",
|
|
99
|
+
"parent_id": "is.null",
|
|
100
|
+
"expires_at": "is.null",
|
|
101
|
+
"message_count": "gt.0",
|
|
102
|
+
"order": "last_message_at.desc",
|
|
103
|
+
"limit": str(limit),
|
|
104
|
+
}
|
|
105
|
+
# RLS also lets Drive shares read a conversation; the picker lists only the user's own.
|
|
106
|
+
if http.cfg.user_id:
|
|
107
|
+
params["user_id"] = f"eq.{http.cfg.user_id}"
|
|
108
|
+
if folder is not None:
|
|
109
|
+
params["scope_id"] = f"eq.{folder}"
|
|
110
|
+
resp = await http.supabase_get(f"/rest/v1/conversations?{urlencode(params)}")
|
|
111
|
+
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
112
|
+
msg = f"HTTP {resp.status_code}: {resp.text[:400]}"
|
|
113
|
+
raise TransportError(msg)
|
|
114
|
+
rows = resp.json() or []
|
|
115
|
+
if not rows:
|
|
116
|
+
return []
|
|
117
|
+
ids = ",".join(str(r["id"]) for r in rows)
|
|
118
|
+
resp = await http.supabase_get(f"/rest/v1/app_drive?{urlencode({'select': 'id,name', 'id': f'in.({ids})'})}")
|
|
119
|
+
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
120
|
+
msg = f"HTTP {resp.status_code}: {resp.text[:400]}"
|
|
121
|
+
raise TransportError(msg)
|
|
122
|
+
names = {str(r["id"]): r.get("name") for r in resp.json() or []}
|
|
123
|
+
return [_row_to_item({**r, "name": names.get(str(r["id"])), "updated_at": r.get("last_message_at")}) for r in rows]
|
|
82
124
|
|
|
83
125
|
|
|
84
126
|
# ---------------------------------------------------------------------------
|
|
@@ -101,7 +143,28 @@ async def fetch_messages(http: AuthedClient, chat_id: str) -> list[dict[str, Any
|
|
|
101
143
|
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
102
144
|
msg = f"HTTP {resp.status_code}: {resp.text[:400]}"
|
|
103
145
|
raise TransportError(msg)
|
|
104
|
-
|
|
146
|
+
rows = resp.json() or []
|
|
147
|
+
if rows:
|
|
148
|
+
return [_message_row_to_openai(r) for r in rows]
|
|
149
|
+
return await _fetch_conversation_messages(http, chat_id)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
async def _fetch_conversation_messages(http: AuthedClient, conversation_id: str) -> list[dict[str, Any]]:
|
|
153
|
+
"""Active items of a unified conversation, mapped to OpenAI format, oldest first."""
|
|
154
|
+
params = {
|
|
155
|
+
"select": (
|
|
156
|
+
"id,seq,revision,type,call_id,tool_name,arguments,superseded_by,created_at,"
|
|
157
|
+
"conversations_parts(position,kind,text,file_id,name,mime)"
|
|
158
|
+
),
|
|
159
|
+
"conversation_id": f"eq.{conversation_id}",
|
|
160
|
+
"superseded_by": "is.null",
|
|
161
|
+
"order": "seq.asc",
|
|
162
|
+
}
|
|
163
|
+
resp = await http.supabase_get(f"/rest/v1/conversations_messages?{urlencode(params)}")
|
|
164
|
+
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
165
|
+
msg = f"HTTP {resp.status_code}: {resp.text[:400]}"
|
|
166
|
+
raise TransportError(msg)
|
|
167
|
+
return rows_to_messages(resp.json() or [])
|
|
105
168
|
|
|
106
169
|
|
|
107
170
|
async def fetch_rewind_points(http: AuthedClient, chat_id: str) -> list[dict[str, Any]]:
|
|
@@ -221,8 +284,7 @@ async def fork_chat(
|
|
|
221
284
|
raise TransportError(msg)
|
|
222
285
|
rows = resp.json() or []
|
|
223
286
|
if not rows:
|
|
224
|
-
|
|
225
|
-
raise TransportError(msg)
|
|
287
|
+
return await _fork_conversation(http, source_chat_id, user_message_count)
|
|
226
288
|
src = rows[0]
|
|
227
289
|
|
|
228
290
|
params = {
|
|
@@ -275,6 +337,52 @@ async def fork_chat(
|
|
|
275
337
|
return new_id, title
|
|
276
338
|
|
|
277
339
|
|
|
340
|
+
async def _fork_conversation(http: AuthedClient, conversation_id: str, user_message_count: int) -> tuple[str, str]:
|
|
341
|
+
"""Fork a unified conversation through the item before its ``user_message_count + 1``-th user message."""
|
|
342
|
+
params = {
|
|
343
|
+
"select": "id,seq,type,conversations_parts(kind,text)",
|
|
344
|
+
"conversation_id": f"eq.{conversation_id}",
|
|
345
|
+
"superseded_by": "is.null",
|
|
346
|
+
"order": "seq.asc",
|
|
347
|
+
}
|
|
348
|
+
resp = await http.supabase_get(f"/rest/v1/conversations_messages?{urlencode(params)}")
|
|
349
|
+
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
350
|
+
msg = f"failed to read messages: HTTP {resp.status_code}: {resp.text[:400]}"
|
|
351
|
+
raise TransportError(msg)
|
|
352
|
+
items = _prefix_until_user_item(resp.json() or [], user_message_count)
|
|
353
|
+
if not items:
|
|
354
|
+
msg = f"chat {conversation_id} has nothing to fork"
|
|
355
|
+
raise TransportError(msg)
|
|
356
|
+
created = await http.json_post(
|
|
357
|
+
f"/conversations/{http.cfg.org_uuid}/{conversation_id}/fork",
|
|
358
|
+
{"through_item_id": str(items[-1]["id"])},
|
|
359
|
+
)
|
|
360
|
+
new_id = str(created["id"])
|
|
361
|
+
resp = await http.supabase_get(f"/rest/v1/app_drive?{urlencode({'select': 'name', 'id': f'eq.{new_id}'})}")
|
|
362
|
+
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
363
|
+
msg = f"failed to read fork: HTTP {resp.status_code}: {resp.text[:400]}"
|
|
364
|
+
raise TransportError(msg)
|
|
365
|
+
nodes = resp.json() or []
|
|
366
|
+
title = f"{(nodes[0].get('name') if nodes else None) or 'Chat'} (fork)"
|
|
367
|
+
await rename_chat(http, new_id, title)
|
|
368
|
+
return new_id, title
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def _prefix_until_user_item(items: list[dict[str, Any]], user_message_count: int) -> list[dict[str, Any]]:
|
|
372
|
+
"""Items up to (excluding) the ``user_message_count + 1``-th user message with text."""
|
|
373
|
+
if user_message_count <= 0:
|
|
374
|
+
return list(items)
|
|
375
|
+
kept: list[dict[str, Any]] = []
|
|
376
|
+
seen = 0
|
|
377
|
+
for item in items:
|
|
378
|
+
if item.get("type") == "user_message" and text_of(item.get("conversations_parts") or []):
|
|
379
|
+
seen += 1
|
|
380
|
+
if seen > user_message_count:
|
|
381
|
+
break
|
|
382
|
+
kept.append(item)
|
|
383
|
+
return kept
|
|
384
|
+
|
|
385
|
+
|
|
278
386
|
def _prefix_until_user(
|
|
279
387
|
messages: list[dict[str, Any]],
|
|
280
388
|
user_message_count: int,
|
|
@@ -339,10 +447,18 @@ async def rename_chat(http: AuthedClient, chat_id: str, name: str) -> None:
|
|
|
339
447
|
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
340
448
|
msg = f"failed to rename chat: HTTP {resp.status_code}: {resp.text[:400]}"
|
|
341
449
|
raise TransportError(msg)
|
|
450
|
+
resp = await http.supabase_patch(
|
|
451
|
+
f"/rest/v1/app_drive?{_conversation_node(chat_id)}",
|
|
452
|
+
body,
|
|
453
|
+
prefer="return=minimal",
|
|
454
|
+
)
|
|
455
|
+
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
456
|
+
msg = f"failed to rename conversation: HTTP {resp.status_code}: {resp.text[:400]}"
|
|
457
|
+
raise TransportError(msg)
|
|
342
458
|
|
|
343
459
|
|
|
344
460
|
async def delete_chat(http: AuthedClient, chat_id: str) -> None:
|
|
345
|
-
"""DELETE one ``app_cli`` row.
|
|
461
|
+
"""DELETE one ``app_cli`` row, or the Drive node of a unified conversation (a trigger deletes the conversation).
|
|
346
462
|
|
|
347
463
|
``app_cli_messages`` rows cascade away via the FK constraint; RLS
|
|
348
464
|
again scopes the DELETE to the owner.
|
|
@@ -351,6 +467,14 @@ async def delete_chat(http: AuthedClient, chat_id: str) -> None:
|
|
|
351
467
|
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
352
468
|
msg = f"failed to delete chat: HTTP {resp.status_code}: {resp.text[:400]}"
|
|
353
469
|
raise TransportError(msg)
|
|
470
|
+
resp = await http.supabase_delete(f"/rest/v1/app_drive?{_conversation_node(chat_id)}")
|
|
471
|
+
if resp.status_code >= HTTP_ERROR_THRESHOLD:
|
|
472
|
+
msg = f"failed to delete conversation: HTTP {resp.status_code}: {resp.text[:400]}"
|
|
473
|
+
raise TransportError(msg)
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def _conversation_node(conversation_id: str) -> str:
|
|
477
|
+
return urlencode({"id": f"eq.{conversation_id}", "represents": "eq.conversation"})
|
|
354
478
|
|
|
355
479
|
|
|
356
480
|
# ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Rows of the unified ``conversations_messages`` table as the OpenAI-style messages replay expects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from operator import itemgetter
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
COMPACTION_SUMMARY_KIND = "compaction_summary"
|
|
9
|
+
ASSISTANT_ITEMS = frozenset({"reasoning", "assistant_message", "function_call"})
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def text_of(parts: list[dict[str, Any]]) -> str:
|
|
13
|
+
"""The item's visible text, pasted text included, in block order."""
|
|
14
|
+
texts = [p.get("text") or "" for p in parts if p.get("kind") in {"text", "pasted_text"}]
|
|
15
|
+
return "\n\n".join(t for t in texts if t)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def add_to_turn(turn: dict[str, Any], item: dict[str, Any], parts: list[dict[str, Any]]) -> None:
|
|
19
|
+
"""Fold one assistant-side item into its turn's single message."""
|
|
20
|
+
kind = item["type"]
|
|
21
|
+
if kind == "reasoning":
|
|
22
|
+
turn["reasoning"] = text_of(parts)
|
|
23
|
+
elif kind == "assistant_message":
|
|
24
|
+
turn["content"] = text_of(parts)
|
|
25
|
+
else:
|
|
26
|
+
call = {
|
|
27
|
+
"id": item.get("call_id") or item["id"],
|
|
28
|
+
"type": "function",
|
|
29
|
+
"function": {"name": item.get("tool_name") or "unknown", "arguments": item.get("arguments") or "{}"},
|
|
30
|
+
}
|
|
31
|
+
turn.setdefault("tool_calls", []).append(call)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def item_to_message(item: dict[str, Any], parts: list[dict[str, Any]], tool_names: dict[str, str]) -> dict[str, Any]:
|
|
35
|
+
"""One user, compaction or tool-output item as an OpenAI-style message."""
|
|
36
|
+
kind = item["type"]
|
|
37
|
+
if kind == "user_message":
|
|
38
|
+
return {"role": "user", "content": text_of(parts)}
|
|
39
|
+
if kind == "compaction":
|
|
40
|
+
return {"role": "user", "kind": COMPACTION_SUMMARY_KIND, "content": text_of(parts)}
|
|
41
|
+
call_id = item.get("call_id") or item["id"]
|
|
42
|
+
return {
|
|
43
|
+
"role": "tool",
|
|
44
|
+
"tool_call_id": call_id,
|
|
45
|
+
"name": item.get("tool_name") or tool_names.get(call_id, ""),
|
|
46
|
+
"content": text_of(parts),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def rows_to_messages(items: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
|
51
|
+
"""Active items, each carrying its embedded ``conversations_parts``, in timeline order."""
|
|
52
|
+
active = sorted((i for i in items if i.get("superseded_by") is None), key=itemgetter("seq"))
|
|
53
|
+
messages: list[dict[str, Any]] = []
|
|
54
|
+
tool_names: dict[str, str] = {}
|
|
55
|
+
turn: dict[str, Any] | None = None
|
|
56
|
+
turn_revision: int | None = None
|
|
57
|
+
for item in active:
|
|
58
|
+
parts = sorted(item.get("conversations_parts") or [], key=itemgetter("position"))
|
|
59
|
+
if item["type"] in ASSISTANT_ITEMS:
|
|
60
|
+
# One stored assistant message is one batch, and a batch shares one revision.
|
|
61
|
+
if turn is None or turn_revision != item.get("revision"):
|
|
62
|
+
turn = {"role": "assistant", "content": None}
|
|
63
|
+
turn_revision = item.get("revision")
|
|
64
|
+
messages.append(turn)
|
|
65
|
+
if item["type"] == "function_call":
|
|
66
|
+
tool_names[item.get("call_id") or item["id"]] = item.get("tool_name") or "unknown"
|
|
67
|
+
add_to_turn(turn, item, parts)
|
|
68
|
+
continue
|
|
69
|
+
turn = None
|
|
70
|
+
messages.append(item_to_message(item, parts, tool_names))
|
|
71
|
+
return messages
|
|
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
|
|
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
|
|
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
|