chattermate-cli 0.8.0__tar.gz → 0.10.0__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.
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/PKG-INFO +34 -2
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/README.md +32 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/__init__.py +1 -1
- chattermate_cli-0.10.0/chattermate_cli/agent_env.py +42 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/client.py +180 -1
- chattermate_cli-0.10.0/chattermate_cli/commands/action.py +165 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/ai.py +1 -1
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/auth.py +14 -1
- chattermate_cli-0.10.0/chattermate_cli/commands/channels.py +83 -0
- chattermate_cli-0.10.0/chattermate_cli/commands/journey.py +258 -0
- chattermate_cli-0.10.0/chattermate_cli/commands/widget.py +116 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/workflow.py +1 -21
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/context.py +24 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/main.py +6 -0
- chattermate_cli-0.10.0/chattermate_cli/mcp_in_app.py +268 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/mcp_server.py +54 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/PKG-INFO +34 -2
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/SOURCES.txt +8 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/requires.txt +1 -1
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/pyproject.toml +2 -2
- chattermate_cli-0.10.0/tests/test_action_journey.py +326 -0
- chattermate_cli-0.10.0/tests/test_channels.py +97 -0
- chattermate_cli-0.10.0/tests/test_mcp.py +282 -0
- chattermate_cli-0.10.0/tests/test_signup_attribution.py +114 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_widget.py +17 -0
- chattermate_cli-0.8.0/chattermate_cli/commands/widget.py +0 -63
- chattermate_cli-0.8.0/tests/test_mcp.py +0 -64
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/LICENSE +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/__init__.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/agent.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/customization.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/help_center.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/knowledge.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/lead_capture.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/commands/ticketing.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli/config.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/dependency_links.txt +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/entry_points.txt +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/top_level.txt +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/setup.cfg +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_ai.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_auth.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_client.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_customization.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_help_center.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_knowledge.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_lead_capture.py +0 -0
- {chattermate_cli-0.8.0 → chattermate_cli-0.10.0}/tests/test_ticketing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chattermate-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: ChatterMate CLI and MCP server — sign up, authenticate, and configure agents, workflows and knowledge from the terminal or an AI agent.
|
|
5
5
|
Author: ChatterMate
|
|
6
6
|
License: AGPL-3.0-or-later
|
|
@@ -10,7 +10,7 @@ License-File: LICENSE
|
|
|
10
10
|
Requires-Dist: typer>=0.12
|
|
11
11
|
Requires-Dist: httpx>=0.27
|
|
12
12
|
Requires-Dist: rich>=13.0
|
|
13
|
-
Requires-Dist: mcp>=1.
|
|
13
|
+
Requires-Dist: mcp>=1.10
|
|
14
14
|
Provides-Extra: test
|
|
15
15
|
Requires-Dist: pytest>=8.0; extra == "test"
|
|
16
16
|
Requires-Dist: respx>=0.21; extra == "test"
|
|
@@ -73,6 +73,23 @@ chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
|
|
|
73
73
|
chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
|
|
74
74
|
chattermate ticketing rca TKT-4 # the root-cause document
|
|
75
75
|
chattermate ticketing settings show
|
|
76
|
+
|
|
77
|
+
# In-app actions: declare what the agent may do in your app (your page registers
|
|
78
|
+
# the code with ChatterMate.registerActions), and limit the widget to your site
|
|
79
|
+
chattermate widget domains <widget-id> --set app.example.com
|
|
80
|
+
chattermate action create <agent-id> --name set_currency --label "Set default currency" \
|
|
81
|
+
--description "Sets the account currency, a 3-letter code" --confirm when_overwriting \
|
|
82
|
+
--parameters '{"type":"object","properties":{"code":{"type":"string"}},"required":["code"]}'
|
|
83
|
+
chattermate action list <agent-id> # shows whether a page has registered each one
|
|
84
|
+
chattermate action update <agent-id> set_currency --confirm always
|
|
85
|
+
|
|
86
|
+
# Journeys (paid plans): start from a template, edit, go live, watch the funnel
|
|
87
|
+
chattermate journey templates <agent-id>
|
|
88
|
+
chattermate journey from-template <agent-id> saas_onboarding --key setup
|
|
89
|
+
chattermate journey show <agent-id> setup > setup.json # edit, then:
|
|
90
|
+
chattermate journey update <agent-id> setup --file setup.json
|
|
91
|
+
chattermate journey status <agent-id> setup live
|
|
92
|
+
chattermate journey funnel <agent-id> setup --days 7
|
|
76
93
|
```
|
|
77
94
|
|
|
78
95
|
Every command accepts `--json` for machine-readable output.
|
|
@@ -117,6 +134,21 @@ Read-only: `whoami`, `list_agents`, `get_agent`, `get_workflow`, `get_workflow_n
|
|
|
117
134
|
Mutating: `create_agent`, `update_agent`, `create_workflow`, `update_workflow`,
|
|
118
135
|
`update_workflow_nodes`, `add_knowledge_url`, `link_knowledge`, `unlink_knowledge`.
|
|
119
136
|
|
|
137
|
+
Widgets: `list_widgets`, `create_widget`, `get_widget_embed_settings`,
|
|
138
|
+
`set_widget_allowed_domains` (in-app actions only run on a widget limited to its site).
|
|
139
|
+
|
|
140
|
+
In-app actions (declared here; the page supplies the code with
|
|
141
|
+
`ChatterMate.registerActions`): `list_actions`, `create_action`, `update_action`,
|
|
142
|
+
`set_action_enabled`, `delete_action`, `preview_action_for_model`.
|
|
143
|
+
|
|
144
|
+
Journeys (paid plans): `list_journeys`, `journey_templates`, `journey_context_keys`,
|
|
145
|
+
`get_journey`, `create_journey`, `create_journey_from_template`, `update_journey`,
|
|
146
|
+
`set_journey_status`, `reorder_journeys`, `delete_journey`, `journey_funnel`,
|
|
147
|
+
`journey_stuck_users`.
|
|
148
|
+
|
|
149
|
+
Help center: `help_center_settings`, `configure_help_center`, `list_faqs`, `create_faq`,
|
|
150
|
+
`update_faq`, `delete_faq`, `import_faqs_from_url`, and more.
|
|
151
|
+
|
|
120
152
|
## Tests
|
|
121
153
|
|
|
122
154
|
```bash
|
|
@@ -55,6 +55,23 @@ chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
|
|
|
55
55
|
chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
|
|
56
56
|
chattermate ticketing rca TKT-4 # the root-cause document
|
|
57
57
|
chattermate ticketing settings show
|
|
58
|
+
|
|
59
|
+
# In-app actions: declare what the agent may do in your app (your page registers
|
|
60
|
+
# the code with ChatterMate.registerActions), and limit the widget to your site
|
|
61
|
+
chattermate widget domains <widget-id> --set app.example.com
|
|
62
|
+
chattermate action create <agent-id> --name set_currency --label "Set default currency" \
|
|
63
|
+
--description "Sets the account currency, a 3-letter code" --confirm when_overwriting \
|
|
64
|
+
--parameters '{"type":"object","properties":{"code":{"type":"string"}},"required":["code"]}'
|
|
65
|
+
chattermate action list <agent-id> # shows whether a page has registered each one
|
|
66
|
+
chattermate action update <agent-id> set_currency --confirm always
|
|
67
|
+
|
|
68
|
+
# Journeys (paid plans): start from a template, edit, go live, watch the funnel
|
|
69
|
+
chattermate journey templates <agent-id>
|
|
70
|
+
chattermate journey from-template <agent-id> saas_onboarding --key setup
|
|
71
|
+
chattermate journey show <agent-id> setup > setup.json # edit, then:
|
|
72
|
+
chattermate journey update <agent-id> setup --file setup.json
|
|
73
|
+
chattermate journey status <agent-id> setup live
|
|
74
|
+
chattermate journey funnel <agent-id> setup --days 7
|
|
58
75
|
```
|
|
59
76
|
|
|
60
77
|
Every command accepts `--json` for machine-readable output.
|
|
@@ -99,6 +116,21 @@ Read-only: `whoami`, `list_agents`, `get_agent`, `get_workflow`, `get_workflow_n
|
|
|
99
116
|
Mutating: `create_agent`, `update_agent`, `create_workflow`, `update_workflow`,
|
|
100
117
|
`update_workflow_nodes`, `add_knowledge_url`, `link_knowledge`, `unlink_knowledge`.
|
|
101
118
|
|
|
119
|
+
Widgets: `list_widgets`, `create_widget`, `get_widget_embed_settings`,
|
|
120
|
+
`set_widget_allowed_domains` (in-app actions only run on a widget limited to its site).
|
|
121
|
+
|
|
122
|
+
In-app actions (declared here; the page supplies the code with
|
|
123
|
+
`ChatterMate.registerActions`): `list_actions`, `create_action`, `update_action`,
|
|
124
|
+
`set_action_enabled`, `delete_action`, `preview_action_for_model`.
|
|
125
|
+
|
|
126
|
+
Journeys (paid plans): `list_journeys`, `journey_templates`, `journey_context_keys`,
|
|
127
|
+
`get_journey`, `create_journey`, `create_journey_from_template`, `update_journey`,
|
|
128
|
+
`set_journey_status`, `reorder_journeys`, `delete_journey`, `journey_funnel`,
|
|
129
|
+
`journey_stuck_users`.
|
|
130
|
+
|
|
131
|
+
Help center: `help_center_settings`, `configure_help_center`, `list_faqs`, `create_faq`,
|
|
132
|
+
`update_faq`, `delete_faq`, `import_faqs_from_url`, and more.
|
|
133
|
+
|
|
102
134
|
## Tests
|
|
103
135
|
|
|
104
136
|
```bash
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ChatterMate CLI
|
|
3
|
+
Copyright (C) 2024 ChatterMate
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Affero General Public License as
|
|
7
|
+
published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
License, or (at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Affero General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
17
|
+
|
|
18
|
+
Which AI coding tool, if any, is running the CLI: read from the environment
|
|
19
|
+
variable each tool sets for the commands it runs. Sent with a signup so the
|
|
20
|
+
reports can tell agent-driven signups apart; nothing else uses it. Cursor
|
|
21
|
+
sets its variable in every terminal it opens, so a person typing in Cursor's
|
|
22
|
+
own terminal counts as "cursor" too.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import os
|
|
26
|
+
from typing import Mapping, Optional
|
|
27
|
+
|
|
28
|
+
# Environment variable the tool sets -> the name recorded for it
|
|
29
|
+
AGENT_ENV_VARS = {
|
|
30
|
+
"CLAUDECODE": "claude-code",
|
|
31
|
+
"CURSOR_TRACE_ID": "cursor",
|
|
32
|
+
"CODEX_SANDBOX": "codex",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def detect_agent(environ: Optional[Mapping[str, str]] = None) -> Optional[str]:
|
|
37
|
+
"""The AI coding tool running this process, or None."""
|
|
38
|
+
env = os.environ if environ is None else environ
|
|
39
|
+
for var, name in AGENT_ENV_VARS.items():
|
|
40
|
+
if env.get(var):
|
|
41
|
+
return name
|
|
42
|
+
return None
|
|
@@ -32,6 +32,51 @@ class ChatterMateError(Exception):
|
|
|
32
32
|
self.status_code = status_code
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
def _find(items: Any, id_or_name: str, name_field: str, missing: str) -> Dict[str, Any]:
|
|
36
|
+
"""The item whose id (any case) or name field matches; names are lowercase by rule."""
|
|
37
|
+
wanted = id_or_name.strip().lower()
|
|
38
|
+
for item in items or []:
|
|
39
|
+
if str(item.get("id", "")).lower() == wanted or item.get(name_field) == id_or_name:
|
|
40
|
+
return item
|
|
41
|
+
raise ChatterMateError(missing, 404)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _merge(current: Dict[str, Any], changes: Dict[str, Any], read_only: frozenset, live_field: str):
|
|
45
|
+
"""The full-replace body: today's values with the changes on top.
|
|
46
|
+
|
|
47
|
+
Read-only fields in changes are ignored (so a fetched object can be sent
|
|
48
|
+
back whole); any field the item doesn't have is refused. live_field is sent
|
|
49
|
+
as it is now, and its new value returned only when the caller changes it,
|
|
50
|
+
for the caller to set through its own endpoint.
|
|
51
|
+
"""
|
|
52
|
+
writable = {k: v for k, v in current.items() if k not in read_only}
|
|
53
|
+
changes = {k: v for k, v in changes.items() if k not in read_only}
|
|
54
|
+
unknown = set(changes) - set(writable)
|
|
55
|
+
if unknown:
|
|
56
|
+
raise ChatterMateError(f"Unknown fields: {', '.join(sorted(unknown))}")
|
|
57
|
+
new_live = changes.pop(live_field, None)
|
|
58
|
+
if new_live == writable.get(live_field):
|
|
59
|
+
new_live = None
|
|
60
|
+
return {**writable, **changes}, new_live
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def build_action_payload(
|
|
64
|
+
name: str, label: str, description: str, confirm: str = "never",
|
|
65
|
+
parameters: Optional[Dict[str, Any]] = None, timeout_s: Optional[int] = None,
|
|
66
|
+
sensitive_form: bool = False, enabled: bool = True,
|
|
67
|
+
) -> Dict[str, Any]:
|
|
68
|
+
"""A new action's body; unset optional fields take the server's defaults."""
|
|
69
|
+
payload: Dict[str, Any] = {
|
|
70
|
+
"name": name, "label": label, "description": description, "confirm": confirm,
|
|
71
|
+
"sensitive_form": sensitive_form, "enabled": enabled,
|
|
72
|
+
}
|
|
73
|
+
if parameters is not None:
|
|
74
|
+
payload["parameters"] = parameters
|
|
75
|
+
if timeout_s is not None:
|
|
76
|
+
payload["timeout_s"] = timeout_s
|
|
77
|
+
return payload
|
|
78
|
+
|
|
79
|
+
|
|
35
80
|
class Client:
|
|
36
81
|
"""
|
|
37
82
|
Thin HTTP wrapper around the ChatterMate API.
|
|
@@ -175,14 +220,18 @@ class Client:
|
|
|
175
220
|
def signup_verify_otp(
|
|
176
221
|
self, email: str, otp: str, admin_name: str, admin_password: str,
|
|
177
222
|
organization_name: str, domain: str, colorcode: Optional[str] = None,
|
|
223
|
+
attribution: Optional[Dict[str, str]] = None,
|
|
178
224
|
) -> Dict[str, Any]:
|
|
179
|
-
"""Enterprise signup step 2: verify OTP and create the org + admin.
|
|
225
|
+
"""Enterprise signup step 2: verify OTP and create the org + admin.
|
|
226
|
+
`attribution` says where the signup came from (client, ref, agent)."""
|
|
180
227
|
body = {
|
|
181
228
|
"email": email, "otp": otp, "name": admin_name, "password": admin_password,
|
|
182
229
|
"organization_name": organization_name, "domain": domain,
|
|
183
230
|
}
|
|
184
231
|
if colorcode:
|
|
185
232
|
body["colorcode"] = colorcode
|
|
233
|
+
if attribution:
|
|
234
|
+
body["attribution"] = attribution
|
|
186
235
|
data = self.request("POST", "/enterprise/signup/verify-otp", json=body, auth=False)
|
|
187
236
|
if isinstance(data, dict) and data.get("access_token"):
|
|
188
237
|
self.token = data.get("access_token")
|
|
@@ -305,6 +354,16 @@ class Client:
|
|
|
305
354
|
def knowledge_queue_status(self, queue_id: int) -> Any:
|
|
306
355
|
return self.request("GET", f"/knowledge/queue/{queue_id}")
|
|
307
356
|
|
|
357
|
+
# -- messaging channels ------------------------------------------------
|
|
358
|
+
|
|
359
|
+
def list_channel_accounts(self) -> Any:
|
|
360
|
+
"""Connected messaging accounts (Slack workspaces, WhatsApp numbers, ...)."""
|
|
361
|
+
return self.request("GET", "/channels/accounts")
|
|
362
|
+
|
|
363
|
+
def set_slack_dm_threads(self, account_id: str, on: bool) -> Any:
|
|
364
|
+
"""Slack: answer each top-level DM in its own thread, as its own conversation."""
|
|
365
|
+
return self.request("PATCH", f"/channels/slack/{account_id}/settings", json={"dm_threads": on})
|
|
366
|
+
|
|
308
367
|
# -- widgets -----------------------------------------------------------
|
|
309
368
|
|
|
310
369
|
def create_widget(self, name: str, agent_id: Optional[str] = None) -> Any:
|
|
@@ -316,6 +375,126 @@ class Client:
|
|
|
316
375
|
def list_widgets_for_agent(self, agent_id: str) -> Any:
|
|
317
376
|
return self.request("GET", f"/widgets/agent/{agent_id}")
|
|
318
377
|
|
|
378
|
+
def get_widget_embed_settings(self, widget_id: str) -> Any:
|
|
379
|
+
return self.request("GET", f"/widgets/{widget_id}/embed-settings")
|
|
380
|
+
|
|
381
|
+
def set_widget_allowed_domains(self, widget_id: str, domains: List[str]) -> Any:
|
|
382
|
+
"""Sites the widget may be embedded on (in-app actions only run on these)."""
|
|
383
|
+
return self.request("PUT", f"/widgets/{widget_id}/embed-settings", json={"allowed_domains": domains})
|
|
384
|
+
|
|
385
|
+
# -- in-app actions ----------------------------------------------------
|
|
386
|
+
|
|
387
|
+
# Fields a response carries that the server sets; never sent back.
|
|
388
|
+
ACTION_READ_ONLY = frozenset({"id", "agent_id", "last_registered_at", "created_at", "updated_at"})
|
|
389
|
+
|
|
390
|
+
def list_actions(self, agent_id: str) -> Any:
|
|
391
|
+
return self.request("GET", f"/agent/{agent_id}/actions")
|
|
392
|
+
|
|
393
|
+
def find_action(self, agent_id: str, id_or_name: str) -> Dict[str, Any]:
|
|
394
|
+
"""An agent's action by its id or its name."""
|
|
395
|
+
listing = self.list_actions(agent_id)
|
|
396
|
+
items = listing.get("actions", []) if isinstance(listing, dict) else listing
|
|
397
|
+
return _find(items, id_or_name, "name", f"No action {id_or_name} on this agent.")
|
|
398
|
+
|
|
399
|
+
def resolve_action_id(self, agent_id: str, id_or_name: str) -> str:
|
|
400
|
+
return str(self.find_action(agent_id, id_or_name)["id"])
|
|
401
|
+
|
|
402
|
+
def update_action(self, agent_id: str, id_or_name: str, changes: Dict[str, Any]) -> Any:
|
|
403
|
+
"""Change only the given fields: the rest are sent back as they are now.
|
|
404
|
+
On/off goes through its own endpoint, so a toggle made meanwhile isn't undone."""
|
|
405
|
+
current = self.find_action(agent_id, id_or_name)
|
|
406
|
+
action_id = str(current["id"])
|
|
407
|
+
payload, enabled = _merge(current, changes, self.ACTION_READ_ONLY, live_field="enabled")
|
|
408
|
+
result = self.replace_action(agent_id, action_id, payload)
|
|
409
|
+
if enabled is not None:
|
|
410
|
+
result = self.set_action_enabled(agent_id, action_id, enabled)
|
|
411
|
+
return result
|
|
412
|
+
|
|
413
|
+
def create_action(self, agent_id: str, payload: Dict[str, Any]) -> Any:
|
|
414
|
+
return self.request("POST", f"/agent/{agent_id}/actions", json=payload)
|
|
415
|
+
|
|
416
|
+
def replace_action(self, agent_id: str, action_id: str, payload: Dict[str, Any]) -> Any:
|
|
417
|
+
"""Full replace: every field is sent."""
|
|
418
|
+
return self.request("PUT", f"/agent/{agent_id}/actions/{action_id}", json=payload)
|
|
419
|
+
|
|
420
|
+
def set_action_enabled(self, agent_id: str, action_id: str, enabled: bool) -> Any:
|
|
421
|
+
return self.request("PATCH", f"/agent/{agent_id}/actions/{action_id}", json={"enabled": enabled})
|
|
422
|
+
|
|
423
|
+
def delete_action(self, agent_id: str, action_id: str) -> Any:
|
|
424
|
+
return self.request("DELETE", f"/agent/{agent_id}/actions/{action_id}")
|
|
425
|
+
|
|
426
|
+
def action_model_view(self, agent_id: str, action_id: str) -> Any:
|
|
427
|
+
"""Exactly what the model is told about the action."""
|
|
428
|
+
return self.request("GET", f"/agent/{agent_id}/actions/{action_id}/model-view")
|
|
429
|
+
|
|
430
|
+
# -- journeys ----------------------------------------------------------
|
|
431
|
+
|
|
432
|
+
# Fields a response carries that the server sets; never sent back.
|
|
433
|
+
JOURNEY_READ_ONLY = frozenset({"id", "agent_id", "version", "created_at", "updated_at"})
|
|
434
|
+
|
|
435
|
+
def list_journeys(self, agent_id: str) -> Any:
|
|
436
|
+
return self.request("GET", f"/agent/{agent_id}/journeys")
|
|
437
|
+
|
|
438
|
+
def find_journey(self, agent_id: str, id_or_key: str) -> Dict[str, Any]:
|
|
439
|
+
"""An agent's journey by its id or its key."""
|
|
440
|
+
return _find(self.list_journeys(agent_id), id_or_key, "key", f"No journey {id_or_key} on this agent.")
|
|
441
|
+
|
|
442
|
+
def resolve_journey_id(self, agent_id: str, id_or_key: str) -> str:
|
|
443
|
+
return str(self.find_journey(agent_id, id_or_key)["id"])
|
|
444
|
+
|
|
445
|
+
def update_journey(self, agent_id: str, id_or_key: str, changes: Dict[str, Any]) -> Any:
|
|
446
|
+
"""Change only the given fields. A definition replaces the whole definition.
|
|
447
|
+
Status goes through its own endpoint, so a pause made meanwhile isn't undone."""
|
|
448
|
+
current = self.find_journey(agent_id, id_or_key)
|
|
449
|
+
journey_id = str(current["id"])
|
|
450
|
+
payload, status = _merge(current, changes, self.JOURNEY_READ_ONLY, live_field="status")
|
|
451
|
+
result = self.replace_journey(agent_id, journey_id, payload)
|
|
452
|
+
if status is not None:
|
|
453
|
+
result = self.set_journey_status(agent_id, journey_id, status)
|
|
454
|
+
return result
|
|
455
|
+
|
|
456
|
+
def journey_templates(self, agent_id: str) -> Any:
|
|
457
|
+
return self.request("GET", f"/agent/{agent_id}/journeys/templates")
|
|
458
|
+
|
|
459
|
+
def journey_context_keys(self, agent_id: str) -> Any:
|
|
460
|
+
return self.request("GET", f"/agent/{agent_id}/journeys/context-keys")
|
|
461
|
+
|
|
462
|
+
def get_journey(self, agent_id: str, journey_id: str) -> Any:
|
|
463
|
+
return self.request("GET", f"/agent/{agent_id}/journeys/{journey_id}")
|
|
464
|
+
|
|
465
|
+
def create_journey(self, agent_id: str, payload: Dict[str, Any]) -> Any:
|
|
466
|
+
return self.request("POST", f"/agent/{agent_id}/journeys", json=payload)
|
|
467
|
+
|
|
468
|
+
def create_journey_from_template(self, agent_id: str, template_key: str, key: Optional[str] = None) -> Any:
|
|
469
|
+
body: Dict[str, Any] = {"template_key": template_key}
|
|
470
|
+
if key:
|
|
471
|
+
body["key"] = key
|
|
472
|
+
return self.request("POST", f"/agent/{agent_id}/journeys/from-template", json=body)
|
|
473
|
+
|
|
474
|
+
def replace_journey(self, agent_id: str, journey_id: str, payload: Dict[str, Any]) -> Any:
|
|
475
|
+
"""Full replace: the whole journey, definition included."""
|
|
476
|
+
return self.request("PUT", f"/agent/{agent_id}/journeys/{journey_id}", json=payload)
|
|
477
|
+
|
|
478
|
+
def set_journey_status(self, agent_id: str, journey_id: str, status: str) -> Any:
|
|
479
|
+
return self.request("PATCH", f"/agent/{agent_id}/journeys/{journey_id}/status", json={"status": status})
|
|
480
|
+
|
|
481
|
+
def reorder_journeys(self, agent_id: str, journeys: List[str]) -> Any:
|
|
482
|
+
"""Priority order, highest first; each entry is a journey's id or key."""
|
|
483
|
+
listing = self.list_journeys(agent_id)
|
|
484
|
+
ids = [str(_find(listing, j, "key", f"No journey {j} on this agent.")["id"]) for j in journeys]
|
|
485
|
+
if len(set(ids)) != len(ids):
|
|
486
|
+
raise ChatterMateError("A journey is listed more than once.")
|
|
487
|
+
return self.request("PUT", f"/agent/{agent_id}/journeys/order", json={"ids": ids})
|
|
488
|
+
|
|
489
|
+
def delete_journey(self, agent_id: str, journey_id: str) -> Any:
|
|
490
|
+
return self.request("DELETE", f"/agent/{agent_id}/journeys/{journey_id}")
|
|
491
|
+
|
|
492
|
+
def journey_funnel(self, agent_id: str, journey_id: str, days: int = 30) -> Any:
|
|
493
|
+
return self.request("GET", f"/agent/{agent_id}/journeys/{journey_id}/funnel", params={"days": days})
|
|
494
|
+
|
|
495
|
+
def journey_stuck_users(self, agent_id: str, journey_id: str, step_id: str) -> Any:
|
|
496
|
+
return self.request("GET", f"/agent/{agent_id}/journeys/{journey_id}/steps/{step_id}/users")
|
|
497
|
+
|
|
319
498
|
# -- AI configuration --------------------------------------------------
|
|
320
499
|
|
|
321
500
|
def setup_ai(self, model_type: str, model_name: str, api_key: str) -> Any:
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ChatterMate - CLI In-App Action Commands
|
|
3
|
+
Copyright (C) 2024 ChatterMate
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Affero General Public License as
|
|
7
|
+
published by the Free Software Foundation, either version 3 of the
|
|
8
|
+
License, or (at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Affero General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any, Dict, Optional
|
|
21
|
+
|
|
22
|
+
import typer
|
|
23
|
+
from rich.table import Table
|
|
24
|
+
|
|
25
|
+
from ..client import build_action_payload
|
|
26
|
+
from ..context import console, get_client, load_json_arg, output, print_error, run
|
|
27
|
+
|
|
28
|
+
action_app = typer.Typer(
|
|
29
|
+
no_args_is_help=True,
|
|
30
|
+
help="In-app actions: things the agent can do inside your web app. Declare them here; "
|
|
31
|
+
"your page supplies the code with ChatterMate.registerActions({ name: handler }).",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
_JSON_OPT = typer.Option(False, "--json", help="Output raw JSON.")
|
|
35
|
+
_CONFIRM_HELP = "never | always (the visitor approves first) | when_overwriting (shows current vs new first)."
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _parameters(data: Optional[str], file: Optional[Path]) -> Optional[Dict[str, Any]]:
|
|
39
|
+
"""The arguments' JSON schema, when one was given."""
|
|
40
|
+
return load_json_arg(data, file) if data is not None or file is not None else None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _print_action(data: Any, verb: str) -> None:
|
|
44
|
+
console.print(f"[green]{verb}[/green] {data.get('name')} ({data.get('id')})")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@action_app.command("list")
|
|
48
|
+
def list_actions(agent_id: str = typer.Argument(..., help="Agent id."), as_json: bool = _JSON_OPT):
|
|
49
|
+
"""List an agent's actions and whether a page has registered code for each."""
|
|
50
|
+
client = get_client()
|
|
51
|
+
data = run(lambda: client.list_actions(agent_id))
|
|
52
|
+
|
|
53
|
+
def render(listing):
|
|
54
|
+
table = Table(title="Actions")
|
|
55
|
+
for col in ("name", "label", "confirm", "enabled", "page has code"):
|
|
56
|
+
table.add_column(col)
|
|
57
|
+
for a in listing.get("actions", []):
|
|
58
|
+
registered = "yes" if a.get("last_registered_at") else "not yet"
|
|
59
|
+
table.add_row(a["name"], a.get("label", ""), a.get("confirm", ""), "on" if a.get("enabled") else "off", registered)
|
|
60
|
+
console.print(table)
|
|
61
|
+
|
|
62
|
+
output(data, as_json, render)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@action_app.command("create")
|
|
66
|
+
def create_action(
|
|
67
|
+
agent_id: str = typer.Argument(..., help="Agent id."),
|
|
68
|
+
name: str = typer.Option(..., "--name", help="lowercase_with_underscores; the page registers code under it."),
|
|
69
|
+
label: str = typer.Option(..., "--label", help="What the visitor sees, e.g. 'Send an invoice'."),
|
|
70
|
+
description: str = typer.Option(..., "--description", help="Tells the model when to use it."),
|
|
71
|
+
parameters: Optional[str] = typer.Option(None, "--parameters", help="JSON schema of the arguments."),
|
|
72
|
+
parameters_file: Optional[Path] = typer.Option(None, "--parameters-file", help="File with the JSON schema."),
|
|
73
|
+
confirm: str = typer.Option("never", "--confirm", help=_CONFIRM_HELP),
|
|
74
|
+
timeout_s: Optional[int] = typer.Option(None, "--timeout", help="Seconds the page gets to run it."),
|
|
75
|
+
sensitive_form: bool = typer.Option(False, "--sensitive-form", help="Only opens a form; never takes IDs, bank or health details."),
|
|
76
|
+
disabled: bool = typer.Option(False, "--disabled", help="Create it turned off."),
|
|
77
|
+
as_json: bool = _JSON_OPT,
|
|
78
|
+
):
|
|
79
|
+
"""Declare an in-app action on an agent."""
|
|
80
|
+
payload = build_action_payload(
|
|
81
|
+
name, label, description, confirm, _parameters(parameters, parameters_file),
|
|
82
|
+
timeout_s, sensitive_form, not disabled,
|
|
83
|
+
)
|
|
84
|
+
client = get_client()
|
|
85
|
+
data = run(lambda: client.create_action(agent_id, payload))
|
|
86
|
+
if as_json:
|
|
87
|
+
output(data, True)
|
|
88
|
+
else:
|
|
89
|
+
_print_action(data, "Created action")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@action_app.command("update")
|
|
93
|
+
def update_action(
|
|
94
|
+
agent_id: str = typer.Argument(..., help="Agent id."),
|
|
95
|
+
action: str = typer.Argument(..., help="Action id or name."),
|
|
96
|
+
name: Optional[str] = typer.Option(None, "--name"),
|
|
97
|
+
label: Optional[str] = typer.Option(None, "--label"),
|
|
98
|
+
description: Optional[str] = typer.Option(None, "--description"),
|
|
99
|
+
parameters: Optional[str] = typer.Option(None, "--parameters", help="JSON schema of the arguments."),
|
|
100
|
+
parameters_file: Optional[Path] = typer.Option(None, "--parameters-file"),
|
|
101
|
+
confirm: Optional[str] = typer.Option(None, "--confirm", help=_CONFIRM_HELP),
|
|
102
|
+
timeout_s: Optional[int] = typer.Option(None, "--timeout"),
|
|
103
|
+
sensitive_form: Optional[bool] = typer.Option(None, "--sensitive-form/--no-sensitive-form"),
|
|
104
|
+
as_json: bool = _JSON_OPT,
|
|
105
|
+
):
|
|
106
|
+
"""Change an action; fields you leave out stay as they are."""
|
|
107
|
+
changes: Dict[str, Any] = {k: v for k, v in {
|
|
108
|
+
"name": name, "label": label, "description": description, "confirm": confirm,
|
|
109
|
+
"timeout_s": timeout_s, "sensitive_form": sensitive_form,
|
|
110
|
+
"parameters": _parameters(parameters, parameters_file),
|
|
111
|
+
}.items() if v is not None}
|
|
112
|
+
if not changes:
|
|
113
|
+
print_error("Nothing to update. Pass at least one option, e.g. --label.")
|
|
114
|
+
raise typer.Exit(code=1)
|
|
115
|
+
client = get_client()
|
|
116
|
+
data = run(lambda: client.update_action(agent_id, action, changes))
|
|
117
|
+
if as_json:
|
|
118
|
+
output(data, True)
|
|
119
|
+
else:
|
|
120
|
+
_print_action(data, "Updated action")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _set_enabled(agent_id: str, action: str, enabled: bool, as_json: bool) -> None:
|
|
124
|
+
client = get_client()
|
|
125
|
+
data = run(lambda: client.set_action_enabled(agent_id, client.resolve_action_id(agent_id, action), enabled))
|
|
126
|
+
if as_json:
|
|
127
|
+
output(data, True)
|
|
128
|
+
else:
|
|
129
|
+
_print_action(data, "Turned on" if enabled else "Turned off")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@action_app.command("enable")
|
|
133
|
+
def enable_action(agent_id: str = typer.Argument(...), action: str = typer.Argument(..., help="Action id or name."),
|
|
134
|
+
as_json: bool = _JSON_OPT):
|
|
135
|
+
"""Turn an action on."""
|
|
136
|
+
_set_enabled(agent_id, action, True, as_json)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@action_app.command("disable")
|
|
140
|
+
def disable_action(agent_id: str = typer.Argument(...), action: str = typer.Argument(..., help="Action id or name."),
|
|
141
|
+
as_json: bool = _JSON_OPT):
|
|
142
|
+
"""Turn an action off: the agent stops being offered it."""
|
|
143
|
+
_set_enabled(agent_id, action, False, as_json)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@action_app.command("delete")
|
|
147
|
+
def delete_action(
|
|
148
|
+
agent_id: str = typer.Argument(...),
|
|
149
|
+
action: str = typer.Argument(..., help="Action id or name."),
|
|
150
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask first."),
|
|
151
|
+
):
|
|
152
|
+
"""Delete an action."""
|
|
153
|
+
client = get_client()
|
|
154
|
+
current = run(lambda: client.find_action(agent_id, action))
|
|
155
|
+
if not yes:
|
|
156
|
+
typer.confirm(f"Delete action {current['name']}?", abort=True)
|
|
157
|
+
run(lambda: client.delete_action(agent_id, str(current["id"])))
|
|
158
|
+
console.print(f"[green]Deleted action[/green] {current['name']}")
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@action_app.command("model-view")
|
|
162
|
+
def model_view(agent_id: str = typer.Argument(...), action: str = typer.Argument(..., help="Action id or name.")):
|
|
163
|
+
"""Show exactly what the model is told about an action."""
|
|
164
|
+
client = get_client()
|
|
165
|
+
output(run(lambda: client.action_model_view(agent_id, client.resolve_action_id(agent_id, action))), True)
|
|
@@ -49,7 +49,7 @@ def setup(
|
|
|
49
49
|
|
|
50
50
|
New organizations already get the ChatterMate model automatically; use this to
|
|
51
51
|
switch to your own provider/key, e.g.:
|
|
52
|
-
chattermate ai setup --model-type openai --model-name gpt-
|
|
52
|
+
chattermate ai setup --model-type openai --model-name gpt-6-luna --api-key sk-...
|
|
53
53
|
"""
|
|
54
54
|
is_managed = model_type.lower() == _DEFAULT_MODEL_TYPE
|
|
55
55
|
if not is_managed and not api_key:
|
|
@@ -23,7 +23,8 @@ from typing import Optional
|
|
|
23
23
|
import typer
|
|
24
24
|
from rich.table import Table
|
|
25
25
|
|
|
26
|
-
from .. import config
|
|
26
|
+
from .. import __version__, config
|
|
27
|
+
from ..agent_env import detect_agent
|
|
27
28
|
from ..client import PAT_PREFIX
|
|
28
29
|
from ..context import console, get_client, output, print_error, run
|
|
29
30
|
|
|
@@ -93,6 +94,13 @@ def _login_with_token(as_json: bool) -> None:
|
|
|
93
94
|
console.print(f"[green]Logged in[/green] as {user.get('email')}")
|
|
94
95
|
|
|
95
96
|
|
|
97
|
+
def signup_attribution(ref: Optional[str]) -> dict:
|
|
98
|
+
"""Where this signup came from: the CLI and its version, the --ref it was
|
|
99
|
+
given and the AI coding tool running it, when there is one."""
|
|
100
|
+
values = {"client": f"cli/{__version__}", "ref": ref, "agent": detect_agent()}
|
|
101
|
+
return {key: value for key, value in values.items() if value}
|
|
102
|
+
|
|
103
|
+
|
|
96
104
|
def signup(
|
|
97
105
|
name: str = typer.Option(..., "--name", prompt=True, help="Organization name."),
|
|
98
106
|
domain: str = typer.Option(..., "--domain", prompt=True, help="Organization domain, e.g. acme.com."),
|
|
@@ -113,6 +121,10 @@ def signup(
|
|
|
113
121
|
help="One-time code emailed to the admin address. If omitted you'll be prompted. "
|
|
114
122
|
"Ignored with --community.",
|
|
115
123
|
),
|
|
124
|
+
ref: Optional[str] = typer.Option(
|
|
125
|
+
None, "--ref",
|
|
126
|
+
help="Where you found this signup, e.g. the prompt you pasted (website-ai-prompt).",
|
|
127
|
+
),
|
|
116
128
|
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
117
129
|
):
|
|
118
130
|
"""Create a new organization and admin user.
|
|
@@ -143,6 +155,7 @@ def signup(
|
|
|
143
155
|
data = run(lambda: client.signup_verify_otp(
|
|
144
156
|
email=admin_email, otp=otp, admin_name=admin_name,
|
|
145
157
|
admin_password=admin_password, organization_name=name, domain=domain,
|
|
158
|
+
attribution=signup_attribution(ref),
|
|
146
159
|
))
|
|
147
160
|
user = data.get("user", {}) if isinstance(data, dict) else {}
|
|
148
161
|
if client.token:
|