chattermate-cli 0.8.1__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.1 → chattermate_cli-0.10.0}/PKG-INFO +34 -2
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/README.md +32 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/__init__.py +1 -1
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/client.py +175 -0
- chattermate_cli-0.10.0/chattermate_cli/commands/action.py +165 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/ai.py +1 -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.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/widget.py +32 -2
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/workflow.py +1 -21
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/context.py +24 -0
- {chattermate_cli-0.8.1 → 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.1 → chattermate_cli-0.10.0}/chattermate_cli/mcp_server.py +54 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/PKG-INFO +34 -2
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/SOURCES.txt +6 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/requires.txt +1 -1
- {chattermate_cli-0.8.1 → 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.8.1/tests/test_mcp.py +0 -64
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/LICENSE +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/agent_env.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/__init__.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/agent.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/auth.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/customization.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/help_center.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/knowledge.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/lead_capture.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/commands/ticketing.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli/config.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/dependency_links.txt +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/entry_points.txt +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/chattermate_cli.egg-info/top_level.txt +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/setup.cfg +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_ai.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_auth.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_client.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_customization.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_help_center.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_knowledge.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_lead_capture.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_signup_attribution.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_ticketing.py +0 -0
- {chattermate_cli-0.8.1 → chattermate_cli-0.10.0}/tests/test_widget.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
|
|
@@ -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.
|
|
@@ -309,6 +354,16 @@ class Client:
|
|
|
309
354
|
def knowledge_queue_status(self, queue_id: int) -> Any:
|
|
310
355
|
return self.request("GET", f"/knowledge/queue/{queue_id}")
|
|
311
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
|
+
|
|
312
367
|
# -- widgets -----------------------------------------------------------
|
|
313
368
|
|
|
314
369
|
def create_widget(self, name: str, agent_id: Optional[str] = None) -> Any:
|
|
@@ -320,6 +375,126 @@ class Client:
|
|
|
320
375
|
def list_widgets_for_agent(self, agent_id: str) -> Any:
|
|
321
376
|
return self.request("GET", f"/widgets/agent/{agent_id}")
|
|
322
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
|
+
|
|
323
498
|
# -- AI configuration --------------------------------------------------
|
|
324
499
|
|
|
325
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:
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ChatterMate - CLI Messaging Channel 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 typing import Optional
|
|
20
|
+
|
|
21
|
+
import typer
|
|
22
|
+
from rich.table import Table
|
|
23
|
+
|
|
24
|
+
from ..context import console, get_client, output, print_error, run
|
|
25
|
+
|
|
26
|
+
channels_app = typer.Typer(no_args_is_help=True, help="Connected messaging channels (Slack, WhatsApp, Telegram, ...).")
|
|
27
|
+
|
|
28
|
+
SLACK = "slack"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _yes_no(value) -> str:
|
|
32
|
+
return "on" if value else "off"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@channels_app.command("list")
|
|
36
|
+
def list_accounts(
|
|
37
|
+
channel: Optional[str] = typer.Option(None, "--channel", help="Only this channel, e.g. slack or whatsapp."),
|
|
38
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
39
|
+
):
|
|
40
|
+
"""List connected channel accounts, the agent each one routes to, and Slack's DM threading."""
|
|
41
|
+
client = get_client()
|
|
42
|
+
rows = run(client.list_channel_accounts) or []
|
|
43
|
+
if channel:
|
|
44
|
+
rows = [r for r in rows if r.get("channel_type") == channel.lower()]
|
|
45
|
+
|
|
46
|
+
def render(accounts):
|
|
47
|
+
table = Table(title="Channel accounts")
|
|
48
|
+
for col in ("id", "channel", "name", "agent_id", "dm threads"):
|
|
49
|
+
table.add_column(col)
|
|
50
|
+
for a in accounts:
|
|
51
|
+
threads = _yes_no(a.get("dm_threads")) if a.get("channel_type") == SLACK else ""
|
|
52
|
+
table.add_row(str(a.get("id")), str(a.get("channel_type", "")), str(a.get("display_name") or ""),
|
|
53
|
+
str(a.get("agent_id") or ""), threads)
|
|
54
|
+
console.print(table)
|
|
55
|
+
|
|
56
|
+
output(rows, as_json, render)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@channels_app.command("slack-threads")
|
|
60
|
+
def slack_threads(
|
|
61
|
+
account_id: str = typer.Argument(..., help="The Slack workspace's account id (from `channels list --channel slack`)."),
|
|
62
|
+
on: Optional[bool] = typer.Option(
|
|
63
|
+
None, "--on/--off",
|
|
64
|
+
help="On: each top-level DM is its own conversation, answered in its thread. Off: one DM conversation.",
|
|
65
|
+
),
|
|
66
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
67
|
+
):
|
|
68
|
+
"""Show or set whether a Slack workspace answers each top-level DM in its own thread."""
|
|
69
|
+
client = get_client()
|
|
70
|
+
if on is None:
|
|
71
|
+
account = next((a for a in run(client.list_channel_accounts) or []
|
|
72
|
+
if str(a.get("id")) == account_id and a.get("channel_type") == SLACK), None)
|
|
73
|
+
if account is None:
|
|
74
|
+
print_error(f"No Slack workspace with account id {account_id}.")
|
|
75
|
+
raise typer.Exit(code=1)
|
|
76
|
+
else:
|
|
77
|
+
account = run(lambda: client.set_slack_dm_threads(account_id, on))
|
|
78
|
+
|
|
79
|
+
def render(a):
|
|
80
|
+
name = a.get("display_name") or a.get("id")
|
|
81
|
+
console.print(f"{name}: thread each direct message [bold]{_yes_no(a.get('dm_threads'))}[/bold]")
|
|
82
|
+
|
|
83
|
+
output(account, as_json, render)
|