chattermate-cli 0.6.0__tar.gz → 0.8.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.6.0 → chattermate_cli-0.8.0}/PKG-INFO +13 -1
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/README.md +12 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/__init__.py +1 -1
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/client.py +35 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/auth.py +43 -11
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/customization.py +6 -5
- chattermate_cli-0.8.0/chattermate_cli/commands/ticketing.py +396 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/main.py +2 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/PKG-INFO +13 -1
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/SOURCES.txt +3 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/pyproject.toml +1 -1
- chattermate_cli-0.8.0/tests/test_auth.py +142 -0
- chattermate_cli-0.8.0/tests/test_ticketing.py +164 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/LICENSE +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/__init__.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/agent.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/ai.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/help_center.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/knowledge.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/lead_capture.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/widget.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/commands/workflow.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/config.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/context.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli/mcp_server.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/dependency_links.txt +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/entry_points.txt +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/requires.txt +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/top_level.txt +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/setup.cfg +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/tests/test_ai.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/tests/test_client.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/tests/test_customization.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/tests/test_help_center.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/tests/test_knowledge.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/tests/test_lead_capture.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/tests/test_mcp.py +0 -0
- {chattermate_cli-0.6.0 → chattermate_cli-0.8.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.8.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
|
|
@@ -48,6 +48,8 @@ local or self-hosted backend, set `CHATTERMATE_API_URL=http://localhost:8000` (o
|
|
|
48
48
|
# Create an organization + admin (community signup), or log in to an existing one
|
|
49
49
|
chattermate signup
|
|
50
50
|
chattermate login --email you@acme.com
|
|
51
|
+
# Signed up with Google or Microsoft? Create a token in Settings → CLI & API tokens, then:
|
|
52
|
+
chattermate login --token
|
|
51
53
|
|
|
52
54
|
chattermate whoami
|
|
53
55
|
|
|
@@ -63,6 +65,14 @@ chattermate workflow get <agent-id>
|
|
|
63
65
|
chattermate workflow create --agent-id <agent-id> --name "Onboarding"
|
|
64
66
|
chattermate knowledge add-url --website https://docs.acme.com --agent-id <agent-id>
|
|
65
67
|
chattermate knowledge status <queue-id>
|
|
68
|
+
|
|
69
|
+
# Inspect AI tickets and drive investigations
|
|
70
|
+
chattermate ticketing list --status open --priority urgent
|
|
71
|
+
chattermate ticketing show TKT-4
|
|
72
|
+
chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
|
|
73
|
+
chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
|
|
74
|
+
chattermate ticketing rca TKT-4 # the root-cause document
|
|
75
|
+
chattermate ticketing settings show
|
|
66
76
|
```
|
|
67
77
|
|
|
68
78
|
Every command accepts `--json` for machine-readable output.
|
|
@@ -75,6 +85,8 @@ Two credentials are supported:
|
|
|
75
85
|
the `CHATTERMATE_TOKEN` environment variable. Long-lived and revocable.
|
|
76
86
|
- **JWT login** — `chattermate login` stores access + refresh tokens in
|
|
77
87
|
`~/.chattermate/config.json` (mode `600`) and refreshes automatically.
|
|
88
|
+
`chattermate login --token` stores a PAT there instead, read from a hidden prompt —
|
|
89
|
+
the way to log in for accounts that use Google or Microsoft sign-in.
|
|
78
90
|
|
|
79
91
|
## MCP server (AI agents)
|
|
80
92
|
|
|
@@ -30,6 +30,8 @@ local or self-hosted backend, set `CHATTERMATE_API_URL=http://localhost:8000` (o
|
|
|
30
30
|
# Create an organization + admin (community signup), or log in to an existing one
|
|
31
31
|
chattermate signup
|
|
32
32
|
chattermate login --email you@acme.com
|
|
33
|
+
# Signed up with Google or Microsoft? Create a token in Settings → CLI & API tokens, then:
|
|
34
|
+
chattermate login --token
|
|
33
35
|
|
|
34
36
|
chattermate whoami
|
|
35
37
|
|
|
@@ -45,6 +47,14 @@ chattermate workflow get <agent-id>
|
|
|
45
47
|
chattermate workflow create --agent-id <agent-id> --name "Onboarding"
|
|
46
48
|
chattermate knowledge add-url --website https://docs.acme.com --agent-id <agent-id>
|
|
47
49
|
chattermate knowledge status <queue-id>
|
|
50
|
+
|
|
51
|
+
# Inspect AI tickets and drive investigations
|
|
52
|
+
chattermate ticketing list --status open --priority urgent
|
|
53
|
+
chattermate ticketing show TKT-4
|
|
54
|
+
chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
|
|
55
|
+
chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
|
|
56
|
+
chattermate ticketing rca TKT-4 # the root-cause document
|
|
57
|
+
chattermate ticketing settings show
|
|
48
58
|
```
|
|
49
59
|
|
|
50
60
|
Every command accepts `--json` for machine-readable output.
|
|
@@ -57,6 +67,8 @@ Two credentials are supported:
|
|
|
57
67
|
the `CHATTERMATE_TOKEN` environment variable. Long-lived and revocable.
|
|
58
68
|
- **JWT login** — `chattermate login` stores access + refresh tokens in
|
|
59
69
|
`~/.chattermate/config.json` (mode `600`) and refreshes automatically.
|
|
70
|
+
`chattermate login --token` stores a PAT there instead, read from a hidden prompt —
|
|
71
|
+
the way to log in for accounts that use Google or Microsoft sign-in.
|
|
60
72
|
|
|
61
73
|
## MCP server (AI agents)
|
|
62
74
|
|
|
@@ -404,3 +404,38 @@ class Client:
|
|
|
404
404
|
|
|
405
405
|
def help_center_job_by_id(self, job_id: int) -> Any:
|
|
406
406
|
return self.request("GET", f"/help-center/jobs/{job_id}")
|
|
407
|
+
|
|
408
|
+
# ---- AI ticketing ----
|
|
409
|
+
def list_tickets(self, params: Optional[Dict[str, Any]] = None) -> Any:
|
|
410
|
+
return self.request("GET", "/tickets", params=params)
|
|
411
|
+
|
|
412
|
+
def ticket_stats(self) -> Any:
|
|
413
|
+
return self.request("GET", "/tickets/stats")
|
|
414
|
+
|
|
415
|
+
def get_ticket(self, ticket_id: str) -> Any:
|
|
416
|
+
return self.request("GET", f"/tickets/{ticket_id}")
|
|
417
|
+
|
|
418
|
+
def comment_ticket(self, ticket_id: str, body: str, is_internal: bool = True) -> Any:
|
|
419
|
+
return self.request(
|
|
420
|
+
"POST",
|
|
421
|
+
f"/tickets/{ticket_id}/comments",
|
|
422
|
+
json={"body": body, "is_internal": is_internal},
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
def investigate_ticket(
|
|
426
|
+
self, ticket_id: str, run_type: str = "investigation", context_note: Optional[str] = None
|
|
427
|
+
) -> Any:
|
|
428
|
+
payload: Dict[str, Any] = {"run_type": run_type}
|
|
429
|
+
if context_note:
|
|
430
|
+
payload["context_note"] = context_note
|
|
431
|
+
return self.request("POST", f"/tickets/{ticket_id}/investigate", json=payload)
|
|
432
|
+
|
|
433
|
+
def ticket_investigation(self, ticket_id: str, run_id: Optional[str] = None) -> Any:
|
|
434
|
+
params = {"run_id": run_id} if run_id else None
|
|
435
|
+
return self.request("GET", f"/tickets/{ticket_id}/investigation", params=params)
|
|
436
|
+
|
|
437
|
+
def get_ticket_settings(self) -> Any:
|
|
438
|
+
return self.request("GET", "/tickets/settings")
|
|
439
|
+
|
|
440
|
+
def update_ticket_settings(self, payload: Dict[str, Any]) -> Any:
|
|
441
|
+
return self.request("PUT", "/tickets/settings", json=payload)
|
|
@@ -24,6 +24,7 @@ import typer
|
|
|
24
24
|
from rich.table import Table
|
|
25
25
|
|
|
26
26
|
from .. import config
|
|
27
|
+
from ..client import PAT_PREFIX
|
|
27
28
|
from ..context import console, get_client, output, print_error, run
|
|
28
29
|
|
|
29
30
|
token_app = typer.Typer(no_args_is_help=True, help="Manage personal access tokens (PATs).")
|
|
@@ -41,13 +42,24 @@ def _store_session(client, user: dict) -> None:
|
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
def login(
|
|
44
|
-
email: str = typer.Option(
|
|
45
|
-
password: str = typer.Option(
|
|
46
|
-
|
|
45
|
+
email: Optional[str] = typer.Option(None, "--email", "-e", help="Account email."),
|
|
46
|
+
password: Optional[str] = typer.Option(None, "--password", "-p", help="Account password."),
|
|
47
|
+
with_token: bool = typer.Option(
|
|
48
|
+
False, "--token",
|
|
49
|
+
help="Log in with a personal access token (cmat_...) from the dashboard. "
|
|
50
|
+
"For accounts that sign in with Google or Microsoft.",
|
|
47
51
|
),
|
|
48
52
|
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
49
53
|
):
|
|
50
|
-
"""Log in and store
|
|
54
|
+
"""Log in and store credentials in ~/.chattermate/config.json."""
|
|
55
|
+
if with_token:
|
|
56
|
+
if email or password:
|
|
57
|
+
print_error("--token can't be combined with --email or --password.")
|
|
58
|
+
raise typer.Exit(code=1)
|
|
59
|
+
_login_with_token(as_json)
|
|
60
|
+
return
|
|
61
|
+
email = email or typer.prompt("Email")
|
|
62
|
+
password = password or typer.prompt("Password", hide_input=True)
|
|
51
63
|
client = get_client(require_auth=False)
|
|
52
64
|
data = run(lambda: client.login(email, password))
|
|
53
65
|
user = data.get("user", {}) if isinstance(data, dict) else {}
|
|
@@ -59,6 +71,28 @@ def login(
|
|
|
59
71
|
console.print("Tip: create a long-lived token for AI agents with 'chattermate token create'.")
|
|
60
72
|
|
|
61
73
|
|
|
74
|
+
def _login_with_token(as_json: bool) -> None:
|
|
75
|
+
"""Store a personal access token once the API accepts it.
|
|
76
|
+
|
|
77
|
+
The token is read from a hidden prompt (never argv, so it stays out of shell
|
|
78
|
+
history and process listings) and checked with whoami before it is saved.
|
|
79
|
+
"""
|
|
80
|
+
token = typer.prompt("Access token", hide_input=True).strip()
|
|
81
|
+
if not token.startswith(PAT_PREFIX):
|
|
82
|
+
print_error(f"That doesn't look like an access token (they start with '{PAT_PREFIX}').")
|
|
83
|
+
raise typer.Exit(code=1)
|
|
84
|
+
client = get_client(require_auth=False)
|
|
85
|
+
client.token, client.refresh_token = token, None
|
|
86
|
+
user = run(client.whoami)
|
|
87
|
+
# Drop any JWT session first: a leftover refresh token must not outlive the switch.
|
|
88
|
+
config.clear_auth()
|
|
89
|
+
_store_session(client, user if isinstance(user, dict) else {})
|
|
90
|
+
if as_json:
|
|
91
|
+
output(user, True)
|
|
92
|
+
else:
|
|
93
|
+
console.print(f"[green]Logged in[/green] as {user.get('email')}")
|
|
94
|
+
|
|
95
|
+
|
|
62
96
|
def signup(
|
|
63
97
|
name: str = typer.Option(..., "--name", prompt=True, help="Organization name."),
|
|
64
98
|
domain: str = typer.Option(..., "--domain", prompt=True, help="Organization domain, e.g. acme.com."),
|
|
@@ -76,8 +110,8 @@ def signup(
|
|
|
76
110
|
),
|
|
77
111
|
otp: Optional[str] = typer.Option(
|
|
78
112
|
None, "--otp",
|
|
79
|
-
help="One-time code emailed to the admin address
|
|
80
|
-
"
|
|
113
|
+
help="One-time code emailed to the admin address. If omitted you'll be prompted. "
|
|
114
|
+
"Ignored with --community.",
|
|
81
115
|
),
|
|
82
116
|
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
83
117
|
):
|
|
@@ -93,8 +127,8 @@ def signup(
|
|
|
93
127
|
client = get_client(require_auth=False)
|
|
94
128
|
|
|
95
129
|
if not community:
|
|
96
|
-
# Only request a
|
|
97
|
-
# Requesting again
|
|
130
|
+
# Only request a code when the caller hasn't already supplied one.
|
|
131
|
+
# (Requesting again re-sends the same code while it is still valid.)
|
|
98
132
|
if not otp:
|
|
99
133
|
run(lambda: client.signup_request_otp(admin_email))
|
|
100
134
|
if not sys.stdin.isatty():
|
|
@@ -105,9 +139,7 @@ def signup(
|
|
|
105
139
|
f"Re-run this command with --otp <code> to complete signup."
|
|
106
140
|
)
|
|
107
141
|
raise typer.Exit(1)
|
|
108
|
-
|
|
109
|
-
hint = " (localhost test code: 123456)" if is_local else ""
|
|
110
|
-
otp = typer.prompt(f"Enter the one-time code emailed to {admin_email}{hint}")
|
|
142
|
+
otp = typer.prompt(f"Enter the one-time code emailed to {admin_email}")
|
|
111
143
|
data = run(lambda: client.signup_verify_otp(
|
|
112
144
|
email=admin_email, otp=otp, admin_name=admin_name,
|
|
113
145
|
admin_password=admin_password, organization_name=name, domain=domain,
|
|
@@ -90,14 +90,15 @@ def set_customization(
|
|
|
90
90
|
None, "--position", help=f"Widget position. One of: {', '.join(WIDGET_POSITIONS)}."),
|
|
91
91
|
font: Optional[str] = typer.Option(None, "--font", help="Font family."),
|
|
92
92
|
custom_css: Optional[str] = typer.Option(None, "--custom-css", help="Custom CSS."),
|
|
93
|
-
# Welcome / messaging
|
|
94
|
-
welcome_title: Optional[str] = typer.Option(None, "--welcome-title"),
|
|
95
|
-
welcome_subtitle: Optional[str] = typer.Option(None, "--welcome-subtitle"),
|
|
96
|
-
welcome_message: Optional[str] = typer.Option(None, "--welcome-message"),
|
|
93
|
+
# Welcome / messaging (max lengths enforced by the API)
|
|
94
|
+
welcome_title: Optional[str] = typer.Option(None, "--welcome-title", help="Welcome title (max 100 chars)."),
|
|
95
|
+
welcome_subtitle: Optional[str] = typer.Option(None, "--welcome-subtitle", help="Welcome subtitle (max 250 chars)."),
|
|
96
|
+
welcome_message: Optional[str] = typer.Option(None, "--welcome-message", help="Welcome message (max 500 chars)."),
|
|
97
97
|
quick_action: List[str] = typer.Option(
|
|
98
98
|
[], "--quick-action", help="Quick-action chip (repeatable; replaces the list)."),
|
|
99
99
|
initiation_message: List[str] = typer.Option(
|
|
100
|
-
[], "--initiation-message",
|
|
100
|
+
[], "--initiation-message",
|
|
101
|
+
help="Proactive launcher nudge, max 100 chars (repeatable; replaces the list)."),
|
|
101
102
|
# Toggles
|
|
102
103
|
show_citations: Optional[bool] = typer.Option(
|
|
103
104
|
None, "--show-citations/--no-show-citations", help="Show knowledge-base citations."),
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ChatterMate - CLI AI Ticketing 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
|
+
Inspect AI tickets and drive investigations from the terminal: list and read
|
|
20
|
+
tickets, watch the glass-box investigation, read the RCA, and kick off a run.
|
|
21
|
+
|
|
22
|
+
Customer-facing and destructive actions (resolving, approving an AI proposal,
|
|
23
|
+
messaging a customer, connector credentials) are deliberately NOT exposed here
|
|
24
|
+
— those belong in the dashboard where there's an audit trail and a human
|
|
25
|
+
looking at what's about to be sent.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
import uuid
|
|
29
|
+
from typing import Any, Dict, Optional
|
|
30
|
+
|
|
31
|
+
import typer
|
|
32
|
+
from rich.table import Table
|
|
33
|
+
|
|
34
|
+
from ..context import console, get_client, output, print_error, run
|
|
35
|
+
|
|
36
|
+
ticketing_app = typer.Typer(
|
|
37
|
+
no_args_is_help=True,
|
|
38
|
+
help="Inspect AI tickets, investigations and RCAs; trigger an investigation.",
|
|
39
|
+
)
|
|
40
|
+
settings_app = typer.Typer(no_args_is_help=True, help="Read and update ticketing settings.")
|
|
41
|
+
ticketing_app.add_typer(settings_app, name="settings")
|
|
42
|
+
|
|
43
|
+
STATUSES = [
|
|
44
|
+
"open", "triaging", "investigating", "awaiting_approval", "in_progress",
|
|
45
|
+
"resolved_pending_confirmation", "resolved", "closed", "reopened",
|
|
46
|
+
]
|
|
47
|
+
PRIORITIES = ["urgent", "high", "medium", "low"]
|
|
48
|
+
|
|
49
|
+
# Confidence bar in the glass box, so `show`/`investigation` read like the UI.
|
|
50
|
+
_BAR_WIDTH = 24
|
|
51
|
+
# The list endpoint caps page_size at 100; ask for the most we can so a
|
|
52
|
+
# number lookup isn't defeated by a busy org (see _resolve_ticket_id).
|
|
53
|
+
_LOOKUP_PAGE_SIZE = 100
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _tickets_of(payload: Any) -> list:
|
|
57
|
+
"""Rows out of a list response. The API returns {"tickets": [...]}."""
|
|
58
|
+
if isinstance(payload, dict):
|
|
59
|
+
return payload.get("tickets") or []
|
|
60
|
+
return payload or []
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _resolve_ticket_id(client, ref: str) -> str:
|
|
64
|
+
"""Accept a TKT-4 / 4 / raw UUID and return the ticket's UUID.
|
|
65
|
+
|
|
66
|
+
The API addresses tickets by UUID, but everyone reads and speaks in
|
|
67
|
+
ticket numbers — so take either. The list endpoint's search matches on
|
|
68
|
+
ticket_number when the term has digits, but it ORs that with a title and
|
|
69
|
+
description LIKE, so a common number can return many rows; we match the
|
|
70
|
+
number exactly and say so honestly when it isn't on the page.
|
|
71
|
+
"""
|
|
72
|
+
ref = (ref or "").strip()
|
|
73
|
+
try:
|
|
74
|
+
return str(uuid.UUID(ref)) # already an id
|
|
75
|
+
except (ValueError, AttributeError, TypeError):
|
|
76
|
+
pass
|
|
77
|
+
digits = ref.upper().removeprefix("TKT-").strip()
|
|
78
|
+
if not digits.isdigit():
|
|
79
|
+
print_error(f"'{ref}' is not a ticket number (TKT-4) or a ticket ID.")
|
|
80
|
+
raise typer.Exit(1)
|
|
81
|
+
|
|
82
|
+
data = client.list_tickets({"search": digits, "page_size": _LOOKUP_PAGE_SIZE})
|
|
83
|
+
rows = _tickets_of(data)
|
|
84
|
+
for t in rows:
|
|
85
|
+
if str(t.get("ticket_number")) == digits:
|
|
86
|
+
return t["id"]
|
|
87
|
+
if len(rows) >= _LOOKUP_PAGE_SIZE:
|
|
88
|
+
print_error(
|
|
89
|
+
f"Could not find TKT-{digits} in the first {_LOOKUP_PAGE_SIZE} search "
|
|
90
|
+
"results — pass the ticket ID instead."
|
|
91
|
+
)
|
|
92
|
+
else:
|
|
93
|
+
print_error(f"No ticket found for '{ref}'.")
|
|
94
|
+
raise typer.Exit(1)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _bar(value: Optional[float]) -> str:
|
|
98
|
+
if value is None:
|
|
99
|
+
return ""
|
|
100
|
+
filled = max(0, min(_BAR_WIDTH, round(float(value) * _BAR_WIDTH)))
|
|
101
|
+
return "█" * filled + "░" * (_BAR_WIDTH - filled)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@ticketing_app.command("list")
|
|
105
|
+
def list_tickets(
|
|
106
|
+
status: Optional[str] = typer.Option(None, "--status", help=f"One of: {', '.join(STATUSES)}."),
|
|
107
|
+
priority: Optional[str] = typer.Option(None, "--priority", help=f"One of: {', '.join(PRIORITIES)}."),
|
|
108
|
+
search: Optional[str] = typer.Option(None, "--search", help="Match title, description or ticket number."),
|
|
109
|
+
limit: int = typer.Option(20, "--limit", help="How many tickets to show."),
|
|
110
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
111
|
+
):
|
|
112
|
+
"""List tickets, newest first."""
|
|
113
|
+
if status and status not in STATUSES:
|
|
114
|
+
print_error(f"Unknown status '{status}'. Expected one of: {', '.join(STATUSES)}")
|
|
115
|
+
raise typer.Exit(1)
|
|
116
|
+
if priority and priority not in PRIORITIES:
|
|
117
|
+
print_error(f"Unknown priority '{priority}'. Expected one of: {', '.join(PRIORITIES)}")
|
|
118
|
+
raise typer.Exit(1)
|
|
119
|
+
|
|
120
|
+
params: Dict[str, Any] = {"page_size": limit}
|
|
121
|
+
if status:
|
|
122
|
+
params["status"] = status
|
|
123
|
+
if priority:
|
|
124
|
+
params["priority"] = priority
|
|
125
|
+
if search:
|
|
126
|
+
params["search"] = search
|
|
127
|
+
|
|
128
|
+
client = get_client()
|
|
129
|
+
data = run(lambda: client.list_tickets(params))
|
|
130
|
+
|
|
131
|
+
def render(payload):
|
|
132
|
+
items = _tickets_of(payload)
|
|
133
|
+
if not items:
|
|
134
|
+
console.print("No tickets found.")
|
|
135
|
+
return
|
|
136
|
+
table = Table(show_header=True, header_style="bold")
|
|
137
|
+
table.add_column("TICKET")
|
|
138
|
+
table.add_column("TITLE")
|
|
139
|
+
table.add_column("STATUS")
|
|
140
|
+
table.add_column("PRIORITY")
|
|
141
|
+
for t in items:
|
|
142
|
+
table.add_row(
|
|
143
|
+
f"TKT-{t.get('ticket_number')}",
|
|
144
|
+
(t.get("title") or "")[:60],
|
|
145
|
+
str(t.get("status") or ""),
|
|
146
|
+
str(t.get("priority") or ""),
|
|
147
|
+
)
|
|
148
|
+
console.print(table)
|
|
149
|
+
|
|
150
|
+
output(data, as_json, render)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@ticketing_app.command("show")
|
|
154
|
+
def show_ticket(
|
|
155
|
+
ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
|
|
156
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
157
|
+
):
|
|
158
|
+
"""Show a ticket: triage, description and recent activity."""
|
|
159
|
+
client = get_client()
|
|
160
|
+
ticket_id = _resolve_ticket_id(client, ticket)
|
|
161
|
+
data = run(lambda: client.get_ticket(ticket_id))
|
|
162
|
+
|
|
163
|
+
def render(payload):
|
|
164
|
+
t = payload.get("ticket") if isinstance(payload, dict) else payload
|
|
165
|
+
if not isinstance(t, dict):
|
|
166
|
+
console.print(str(payload))
|
|
167
|
+
return
|
|
168
|
+
console.print(f"[bold]TKT-{t.get('ticket_number')}[/bold] {t.get('title') or ''}")
|
|
169
|
+
console.print(f" status: {t.get('status')}")
|
|
170
|
+
console.print(f" priority: {t.get('priority')} severity: {t.get('severity') or '-'}")
|
|
171
|
+
if t.get("intent"):
|
|
172
|
+
conf = t.get("triage_confidence")
|
|
173
|
+
conf_txt = f" ({conf})" if conf is not None else ""
|
|
174
|
+
console.print(f" intent: {t.get('intent')}{conf_txt}")
|
|
175
|
+
if t.get("ai_summary"):
|
|
176
|
+
console.print(f"\n [bold]AI summary[/bold]\n {t['ai_summary']}")
|
|
177
|
+
if t.get("description"):
|
|
178
|
+
console.print(f"\n [bold]Description[/bold]\n {t['description']}")
|
|
179
|
+
activities = payload.get("activities") if isinstance(payload, dict) else None
|
|
180
|
+
if activities:
|
|
181
|
+
console.print("\n [bold]Recent activity[/bold]")
|
|
182
|
+
for a in activities[-8:]:
|
|
183
|
+
body = (a.get("body") or "").replace("\n", " ")[:90]
|
|
184
|
+
console.print(f" - [{a.get('activity_type')}] {body}")
|
|
185
|
+
|
|
186
|
+
output(data, as_json, render)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@ticketing_app.command("investigation")
|
|
190
|
+
def show_investigation(
|
|
191
|
+
ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
|
|
192
|
+
run_id: Optional[str] = typer.Option(None, "--run", help="A specific run; defaults to the latest."),
|
|
193
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
194
|
+
):
|
|
195
|
+
"""Show the glass box: hypotheses, verdicts and evidence counts."""
|
|
196
|
+
client = get_client()
|
|
197
|
+
ticket_id = _resolve_ticket_id(client, ticket)
|
|
198
|
+
data = run(lambda: client.ticket_investigation(ticket_id, run_id))
|
|
199
|
+
|
|
200
|
+
def render(payload):
|
|
201
|
+
if not isinstance(payload, dict):
|
|
202
|
+
console.print(str(payload))
|
|
203
|
+
return
|
|
204
|
+
run_info = payload.get("run") or {}
|
|
205
|
+
if not run_info:
|
|
206
|
+
console.print("No investigation has run for this ticket yet.")
|
|
207
|
+
return
|
|
208
|
+
console.print(
|
|
209
|
+
f"[bold]{run_info.get('run_type')}[/bold] · {run_info.get('status')} · "
|
|
210
|
+
f"{run_info.get('llm_calls', 0)} LLM calls · "
|
|
211
|
+
f"{run_info.get('tool_calls_used', 0)}/{run_info.get('max_tool_calls', '-')} tool calls"
|
|
212
|
+
)
|
|
213
|
+
if run_info.get("model_name"):
|
|
214
|
+
console.print(f" model: {run_info['model_name']}")
|
|
215
|
+
if run_info.get("error"):
|
|
216
|
+
console.print(f" [red]error:[/red] {run_info['error']}")
|
|
217
|
+
|
|
218
|
+
for h in payload.get("hypotheses") or []:
|
|
219
|
+
conf = h.get("confidence")
|
|
220
|
+
console.print(
|
|
221
|
+
f"\n H{h.get('idx')} {h.get('title')}\n"
|
|
222
|
+
f" {h.get('status')} {_bar(conf)} {conf if conf is not None else ''}"
|
|
223
|
+
)
|
|
224
|
+
events = payload.get("events") or []
|
|
225
|
+
if events:
|
|
226
|
+
console.print(f"\n {len(events)} evidence event(s) recorded.")
|
|
227
|
+
|
|
228
|
+
output(data, as_json, render)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@ticketing_app.command("rca")
|
|
232
|
+
def show_rca(
|
|
233
|
+
ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
|
|
234
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
235
|
+
):
|
|
236
|
+
"""Print the root-cause analysis document for a ticket."""
|
|
237
|
+
client = get_client()
|
|
238
|
+
ticket_id = _resolve_ticket_id(client, ticket)
|
|
239
|
+
data = run(lambda: client.ticket_investigation(ticket_id))
|
|
240
|
+
|
|
241
|
+
def render(payload):
|
|
242
|
+
rca = (payload or {}).get("rca") if isinstance(payload, dict) else None
|
|
243
|
+
if not rca:
|
|
244
|
+
console.print("No RCA document yet — run an investigation first.")
|
|
245
|
+
return
|
|
246
|
+
version = rca.get("version")
|
|
247
|
+
console.print(f"[bold]Root-cause analysis[/bold] (v{version})\n")
|
|
248
|
+
for key, label in [
|
|
249
|
+
("summary", "Summary"),
|
|
250
|
+
("impact", "Impact"),
|
|
251
|
+
("investigation_log", "Investigation log"),
|
|
252
|
+
("contributing_factors", "Contributing factors"),
|
|
253
|
+
("conclusion", "Conclusion"),
|
|
254
|
+
("remediation", "Remediation"),
|
|
255
|
+
("prevention", "Prevention"),
|
|
256
|
+
("customer_summary", "Customer summary"),
|
|
257
|
+
]:
|
|
258
|
+
value = rca.get(key)
|
|
259
|
+
if not value:
|
|
260
|
+
continue
|
|
261
|
+
if isinstance(value, list):
|
|
262
|
+
value = "\n ".join(f"- {v}" for v in value)
|
|
263
|
+
console.print(f"[bold]{label}[/bold]\n {value}\n")
|
|
264
|
+
|
|
265
|
+
output(data, as_json, render)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@ticketing_app.command("investigate")
|
|
269
|
+
def investigate(
|
|
270
|
+
ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
|
|
271
|
+
triage_only: bool = typer.Option(False, "--triage-only", help="Run triage instead of a full investigation."),
|
|
272
|
+
note: Optional[str] = typer.Option(None, "--note", help="Extra context to steer the run."),
|
|
273
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
274
|
+
):
|
|
275
|
+
"""Queue an AI run for a ticket. The worker picks it up within ~15s."""
|
|
276
|
+
client = get_client()
|
|
277
|
+
ticket_id = _resolve_ticket_id(client, ticket)
|
|
278
|
+
run_type = "triage" if triage_only else "investigation"
|
|
279
|
+
data = run(lambda: client.investigate_ticket(ticket_id, run_type=run_type, context_note=note))
|
|
280
|
+
|
|
281
|
+
def render(payload):
|
|
282
|
+
console.print(
|
|
283
|
+
f"Queued {run_type} run [bold]{(payload or {}).get('id', '')}[/bold] — "
|
|
284
|
+
f"follow it with: chattermate ticketing investigation {ticket}"
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
output(data, as_json, render)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
@ticketing_app.command("comment")
|
|
291
|
+
def comment(
|
|
292
|
+
ticket: str = typer.Argument(..., help="Ticket number (TKT-4) or ID."),
|
|
293
|
+
body: str = typer.Argument(..., help="The note text."),
|
|
294
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
295
|
+
):
|
|
296
|
+
"""Add an internal note to a ticket.
|
|
297
|
+
|
|
298
|
+
Internal only, by design — anything the customer would receive goes through
|
|
299
|
+
the dashboard, where a human sees it before it is sent.
|
|
300
|
+
"""
|
|
301
|
+
client = get_client()
|
|
302
|
+
ticket_id = _resolve_ticket_id(client, ticket)
|
|
303
|
+
data = run(lambda: client.comment_ticket(ticket_id, body, is_internal=True))
|
|
304
|
+
|
|
305
|
+
def render(_payload):
|
|
306
|
+
console.print(f"Added internal note to {ticket}.")
|
|
307
|
+
|
|
308
|
+
output(data, as_json, render)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
@ticketing_app.command("stats")
|
|
312
|
+
def stats(as_json: bool = typer.Option(False, "--json", help="Output raw JSON.")):
|
|
313
|
+
"""Workspace counters: open, awaiting approval, SLA breaching, AI-resolved."""
|
|
314
|
+
client = get_client()
|
|
315
|
+
data = run(lambda: client.ticket_stats())
|
|
316
|
+
|
|
317
|
+
def render(payload):
|
|
318
|
+
if not isinstance(payload, dict):
|
|
319
|
+
console.print(str(payload))
|
|
320
|
+
return
|
|
321
|
+
for key, value in payload.items():
|
|
322
|
+
console.print(f" {key.replace('_', ' '):<24} {value}")
|
|
323
|
+
|
|
324
|
+
output(data, as_json, render)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
@settings_app.command("show")
|
|
328
|
+
def settings_show(as_json: bool = typer.Option(False, "--json", help="Output raw JSON.")):
|
|
329
|
+
"""Show the organization's ticketing settings."""
|
|
330
|
+
client = get_client()
|
|
331
|
+
data = run(lambda: client.get_ticket_settings())
|
|
332
|
+
|
|
333
|
+
def render(cfg):
|
|
334
|
+
if not isinstance(cfg, dict):
|
|
335
|
+
console.print(str(cfg))
|
|
336
|
+
return
|
|
337
|
+
levels = {1: "L1 investigate only", 2: "L2 propose, human approves", 3: "L3 auto-resolve"}
|
|
338
|
+
level = cfg.get("autonomy_level")
|
|
339
|
+
console.print(f" autonomy: {level} — {levels.get(level, '')}")
|
|
340
|
+
console.print(f" auto-investigate: {cfg.get('auto_investigate_on_create')}")
|
|
341
|
+
console.print(f" min confidence (L3): {cfg.get('min_confidence_to_auto_resolve')}")
|
|
342
|
+
console.print(f" confirm timeout: {cfg.get('confirmation_timeout_hours')}h")
|
|
343
|
+
console.print(f" CSAT: {cfg.get('csat_enabled')}")
|
|
344
|
+
console.print(f" max tool calls/run: {cfg.get('max_tool_calls_per_run')}")
|
|
345
|
+
console.print(f" max runs/ticket: {cfg.get('max_runs_per_ticket')}")
|
|
346
|
+
console.print(f" jira escalation: {cfg.get('jira_escalation_enabled')}")
|
|
347
|
+
console.print(f" alert webhook: {cfg.get('alert_webhook_enabled')}")
|
|
348
|
+
|
|
349
|
+
output(data, as_json, render)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
@settings_app.command("set")
|
|
353
|
+
def settings_set(
|
|
354
|
+
autonomy: Optional[int] = typer.Option(None, "--autonomy", min=1, max=3, help="1, 2 or 3."),
|
|
355
|
+
auto_investigate: Optional[bool] = typer.Option(
|
|
356
|
+
None, "--auto-investigate/--no-auto-investigate", help="Triage every new ticket automatically."
|
|
357
|
+
),
|
|
358
|
+
csat: Optional[bool] = typer.Option(None, "--csat/--no-csat", help="Ask for CSAT after resolution."),
|
|
359
|
+
min_confidence: Optional[float] = typer.Option(
|
|
360
|
+
None, "--min-confidence", min=0.0, max=1.0, help="L3 auto-resolve confidence floor."
|
|
361
|
+
),
|
|
362
|
+
confirm_timeout: Optional[int] = typer.Option(
|
|
363
|
+
None, "--confirm-timeout", help="Hours to wait for a customer reply before closing."
|
|
364
|
+
),
|
|
365
|
+
max_tool_calls: Optional[int] = typer.Option(None, "--max-tool-calls", help="Tool-call budget per run."),
|
|
366
|
+
max_runs: Optional[int] = typer.Option(None, "--max-runs", help="Investigation runs per ticket."),
|
|
367
|
+
as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
|
|
368
|
+
):
|
|
369
|
+
"""Update ticketing settings. Only the flags you pass are changed."""
|
|
370
|
+
payload: Dict[str, Any] = {}
|
|
371
|
+
if autonomy is not None:
|
|
372
|
+
payload["autonomy_level"] = autonomy
|
|
373
|
+
if auto_investigate is not None:
|
|
374
|
+
payload["auto_investigate_on_create"] = auto_investigate
|
|
375
|
+
if csat is not None:
|
|
376
|
+
payload["csat_enabled"] = csat
|
|
377
|
+
if min_confidence is not None:
|
|
378
|
+
payload["min_confidence_to_auto_resolve"] = min_confidence
|
|
379
|
+
if confirm_timeout is not None:
|
|
380
|
+
payload["confirmation_timeout_hours"] = confirm_timeout
|
|
381
|
+
if max_tool_calls is not None:
|
|
382
|
+
payload["max_tool_calls_per_run"] = max_tool_calls
|
|
383
|
+
if max_runs is not None:
|
|
384
|
+
payload["max_runs_per_ticket"] = max_runs
|
|
385
|
+
|
|
386
|
+
if not payload:
|
|
387
|
+
print_error("Nothing to update — pass at least one option (see --help).")
|
|
388
|
+
raise typer.Exit(1)
|
|
389
|
+
|
|
390
|
+
client = get_client()
|
|
391
|
+
data = run(lambda: client.update_ticket_settings(payload))
|
|
392
|
+
|
|
393
|
+
def render(_cfg):
|
|
394
|
+
console.print("Ticketing settings updated: " + ", ".join(sorted(payload)))
|
|
395
|
+
|
|
396
|
+
output(data, as_json, render)
|
|
@@ -28,6 +28,7 @@ from .commands.customization import customization_app
|
|
|
28
28
|
from .commands.help_center import help_center_app
|
|
29
29
|
from .commands.knowledge import knowledge_app
|
|
30
30
|
from .commands.lead_capture import lead_app
|
|
31
|
+
from .commands.ticketing import ticketing_app
|
|
31
32
|
from .commands.widget import widget_app
|
|
32
33
|
from .commands.workflow import workflow_app
|
|
33
34
|
|
|
@@ -74,6 +75,7 @@ app.add_typer(knowledge_app, name="knowledge")
|
|
|
74
75
|
app.add_typer(lead_app, name="lead-capture")
|
|
75
76
|
app.add_typer(customization_app, name="customization")
|
|
76
77
|
app.add_typer(help_center_app, name="help-center")
|
|
78
|
+
app.add_typer(ticketing_app, name="ticketing")
|
|
77
79
|
|
|
78
80
|
|
|
79
81
|
def main():
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chattermate-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.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
|
|
@@ -48,6 +48,8 @@ local or self-hosted backend, set `CHATTERMATE_API_URL=http://localhost:8000` (o
|
|
|
48
48
|
# Create an organization + admin (community signup), or log in to an existing one
|
|
49
49
|
chattermate signup
|
|
50
50
|
chattermate login --email you@acme.com
|
|
51
|
+
# Signed up with Google or Microsoft? Create a token in Settings → CLI & API tokens, then:
|
|
52
|
+
chattermate login --token
|
|
51
53
|
|
|
52
54
|
chattermate whoami
|
|
53
55
|
|
|
@@ -63,6 +65,14 @@ chattermate workflow get <agent-id>
|
|
|
63
65
|
chattermate workflow create --agent-id <agent-id> --name "Onboarding"
|
|
64
66
|
chattermate knowledge add-url --website https://docs.acme.com --agent-id <agent-id>
|
|
65
67
|
chattermate knowledge status <queue-id>
|
|
68
|
+
|
|
69
|
+
# Inspect AI tickets and drive investigations
|
|
70
|
+
chattermate ticketing list --status open --priority urgent
|
|
71
|
+
chattermate ticketing show TKT-4
|
|
72
|
+
chattermate ticketing investigate TKT-4 --note "check the payment gateway first"
|
|
73
|
+
chattermate ticketing investigation TKT-4 # hypotheses, verdicts, confidence
|
|
74
|
+
chattermate ticketing rca TKT-4 # the root-cause document
|
|
75
|
+
chattermate ticketing settings show
|
|
66
76
|
```
|
|
67
77
|
|
|
68
78
|
Every command accepts `--json` for machine-readable output.
|
|
@@ -75,6 +85,8 @@ Two credentials are supported:
|
|
|
75
85
|
the `CHATTERMATE_TOKEN` environment variable. Long-lived and revocable.
|
|
76
86
|
- **JWT login** — `chattermate login` stores access + refresh tokens in
|
|
77
87
|
`~/.chattermate/config.json` (mode `600`) and refreshes automatically.
|
|
88
|
+
`chattermate login --token` stores a PAT there instead, read from a hidden prompt —
|
|
89
|
+
the way to log in for accounts that use Google or Microsoft sign-in.
|
|
78
90
|
|
|
79
91
|
## MCP server (AI agents)
|
|
80
92
|
|
|
@@ -21,13 +21,16 @@ chattermate_cli/commands/customization.py
|
|
|
21
21
|
chattermate_cli/commands/help_center.py
|
|
22
22
|
chattermate_cli/commands/knowledge.py
|
|
23
23
|
chattermate_cli/commands/lead_capture.py
|
|
24
|
+
chattermate_cli/commands/ticketing.py
|
|
24
25
|
chattermate_cli/commands/widget.py
|
|
25
26
|
chattermate_cli/commands/workflow.py
|
|
26
27
|
tests/test_ai.py
|
|
28
|
+
tests/test_auth.py
|
|
27
29
|
tests/test_client.py
|
|
28
30
|
tests/test_customization.py
|
|
29
31
|
tests/test_help_center.py
|
|
30
32
|
tests/test_knowledge.py
|
|
31
33
|
tests/test_lead_capture.py
|
|
32
34
|
tests/test_mcp.py
|
|
35
|
+
tests/test_ticketing.py
|
|
33
36
|
tests/test_widget.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "chattermate-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.8.0"
|
|
8
8
|
description = "ChatterMate CLI and MCP server — sign up, authenticate, and configure agents, workflows and knowledge from the terminal or an AI agent."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ChatterMate - CLI Auth Command Tests
|
|
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
|
+
import httpx
|
|
20
|
+
import pytest
|
|
21
|
+
from typer.testing import CliRunner
|
|
22
|
+
|
|
23
|
+
from chattermate_cli import config, context
|
|
24
|
+
from chattermate_cli.commands import auth as auth_cmd
|
|
25
|
+
from chattermate_cli.main import app
|
|
26
|
+
|
|
27
|
+
runner = CliRunner()
|
|
28
|
+
|
|
29
|
+
TOKEN = "cmat_live_secret_123"
|
|
30
|
+
USER = {"id": "u1", "email": "sso@acme.com", "organization_id": "o1", "role": {"name": "Admin"}}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.fixture
|
|
34
|
+
def api(monkeypatch, tmp_path):
|
|
35
|
+
"""Isolated config dir plus a fake API that accepts only TOKEN.
|
|
36
|
+
|
|
37
|
+
Commands still build their client through the real get_client, so token
|
|
38
|
+
resolution from config is exercised; only the HTTP transport is faked.
|
|
39
|
+
"""
|
|
40
|
+
monkeypatch.setenv(config.ENV_CONFIG_DIR, str(tmp_path))
|
|
41
|
+
monkeypatch.delenv(config.ENV_TOKEN, raising=False)
|
|
42
|
+
monkeypatch.setenv(config.ENV_API_URL, "http://test")
|
|
43
|
+
seen = []
|
|
44
|
+
|
|
45
|
+
def handler(request):
|
|
46
|
+
seen.append(request)
|
|
47
|
+
if request.headers.get("Authorization") != f"Bearer {TOKEN}":
|
|
48
|
+
return httpx.Response(401, json={"detail": "Could not validate credentials"})
|
|
49
|
+
assert (request.method, request.url.path) == ("PATCH", "/api/v1/users/me")
|
|
50
|
+
return httpx.Response(200, json=USER)
|
|
51
|
+
|
|
52
|
+
def mocked_client(require_auth=True):
|
|
53
|
+
client = context.get_client(require_auth)
|
|
54
|
+
client._http = httpx.Client(transport=httpx.MockTransport(handler))
|
|
55
|
+
return client
|
|
56
|
+
|
|
57
|
+
monkeypatch.setattr(auth_cmd, "get_client", mocked_client)
|
|
58
|
+
return seen
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_login_token_stores_token_and_whoami_uses_it(api):
|
|
62
|
+
result = runner.invoke(app, ["login", "--token"], input=f"{TOKEN}\n")
|
|
63
|
+
assert result.exit_code == 0, result.output
|
|
64
|
+
assert "Logged in as sso@acme.com" in result.output
|
|
65
|
+
# Hidden prompt: the secret is never echoed back.
|
|
66
|
+
assert TOKEN not in result.output
|
|
67
|
+
|
|
68
|
+
cfg = config.load_config()
|
|
69
|
+
assert cfg["access_token"] == TOKEN
|
|
70
|
+
assert cfg["email"] == "sso@acme.com"
|
|
71
|
+
assert cfg["organization_id"] == "o1"
|
|
72
|
+
|
|
73
|
+
result = runner.invoke(app, ["whoami", "--json"])
|
|
74
|
+
assert result.exit_code == 0, result.output
|
|
75
|
+
assert "sso@acme.com" in result.output
|
|
76
|
+
assert api[-1].headers["Authorization"] == f"Bearer {TOKEN}"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_login_token_replaces_a_password_session(api):
|
|
80
|
+
config.update_config(access_token="jwt-old", refresh_token="jwt-refresh", email="old@acme.com")
|
|
81
|
+
result = runner.invoke(app, ["login", "--token"], input=f"{TOKEN}\n")
|
|
82
|
+
assert result.exit_code == 0, result.output
|
|
83
|
+
cfg = config.load_config()
|
|
84
|
+
assert cfg["access_token"] == TOKEN
|
|
85
|
+
assert "refresh_token" not in cfg
|
|
86
|
+
assert cfg["email"] == "sso@acme.com"
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_login_token_rejected_by_api_stores_nothing(api):
|
|
90
|
+
config.update_config(access_token="jwt-old")
|
|
91
|
+
result = runner.invoke(app, ["login", "--token"], input="cmat_revoked\n")
|
|
92
|
+
assert result.exit_code == 1
|
|
93
|
+
assert "Could not validate credentials" in result.output
|
|
94
|
+
assert config.load_config()["access_token"] == "jwt-old"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_login_token_refuses_something_that_is_not_a_token(api):
|
|
98
|
+
result = runner.invoke(app, ["login", "--token"], input="hunter2\n")
|
|
99
|
+
assert result.exit_code == 1
|
|
100
|
+
assert "cmat_" in result.output
|
|
101
|
+
assert api == [] # never sent anywhere
|
|
102
|
+
assert config.load_config() == {}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_login_token_takes_no_value_on_the_command_line(api):
|
|
106
|
+
# --token is a flag; a secret passed after it is an unexpected argument.
|
|
107
|
+
result = runner.invoke(app, ["login", "--token", TOKEN])
|
|
108
|
+
assert result.exit_code != 0
|
|
109
|
+
assert config.load_config() == {}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_login_token_refuses_email_or_password_alongside(api):
|
|
113
|
+
result = runner.invoke(app, ["login", "--token", "--email", "a@acme.com"], input=f"{TOKEN}\n")
|
|
114
|
+
assert result.exit_code == 1
|
|
115
|
+
assert "can't be combined" in result.output
|
|
116
|
+
assert api == []
|
|
117
|
+
assert config.load_config() == {}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_password_login_still_prompts(monkeypatch, tmp_path):
|
|
121
|
+
monkeypatch.setenv(config.ENV_CONFIG_DIR, str(tmp_path))
|
|
122
|
+
monkeypatch.setenv(config.ENV_API_URL, "http://test")
|
|
123
|
+
|
|
124
|
+
def handler(request):
|
|
125
|
+
assert request.url.path == "/api/v1/users/login"
|
|
126
|
+
assert b"username=admin%40acme.com" in request.content
|
|
127
|
+
assert b"password=pw" in request.content
|
|
128
|
+
return httpx.Response(200, json={
|
|
129
|
+
"access_token": "jwt-access", "refresh_token": "jwt-refresh",
|
|
130
|
+
"user": {"id": "u1", "email": "admin@acme.com", "organization_id": "o1"},
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
def mocked_client(require_auth=True):
|
|
134
|
+
client = context.get_client(require_auth)
|
|
135
|
+
client._http = httpx.Client(transport=httpx.MockTransport(handler))
|
|
136
|
+
return client
|
|
137
|
+
|
|
138
|
+
monkeypatch.setattr(auth_cmd, "get_client", mocked_client)
|
|
139
|
+
result = runner.invoke(app, ["login"], input="admin@acme.com\npw\n")
|
|
140
|
+
assert result.exit_code == 0, result.output
|
|
141
|
+
assert "Logged in as admin@acme.com" in result.output
|
|
142
|
+
assert config.load_config()["refresh_token"] == "jwt-refresh"
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ChatterMate - CLI AI Ticketing Command Tests
|
|
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
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
import pytest
|
|
13
|
+
import typer
|
|
14
|
+
|
|
15
|
+
from chattermate_cli.client import Client
|
|
16
|
+
from chattermate_cli.commands.ticketing import _resolve_ticket_id
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def make_client(handler, token="cmat_x"):
|
|
20
|
+
client = Client(api_url="http://test", token=token)
|
|
21
|
+
client._http = httpx.Client(transport=httpx.MockTransport(handler))
|
|
22
|
+
return client
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# ---------- client paths ----------
|
|
26
|
+
|
|
27
|
+
def test_list_tickets_path_and_params():
|
|
28
|
+
seen = {}
|
|
29
|
+
|
|
30
|
+
def handler(request):
|
|
31
|
+
seen["method"] = request.method
|
|
32
|
+
seen["path"] = request.url.path
|
|
33
|
+
seen["query"] = dict(request.url.params)
|
|
34
|
+
return httpx.Response(200, json={"tickets": [], "pagination": {}})
|
|
35
|
+
|
|
36
|
+
make_client(handler).list_tickets({"status": "open", "page_size": 5})
|
|
37
|
+
|
|
38
|
+
assert seen["method"] == "GET"
|
|
39
|
+
assert seen["path"] == "/api/v1/tickets"
|
|
40
|
+
assert seen["query"]["status"] == "open"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_investigate_posts_run_type_and_note():
|
|
44
|
+
seen = {}
|
|
45
|
+
|
|
46
|
+
def handler(request):
|
|
47
|
+
import json as _json
|
|
48
|
+
seen["method"] = request.method
|
|
49
|
+
seen["path"] = request.url.path
|
|
50
|
+
seen["body"] = _json.loads(request.content)
|
|
51
|
+
return httpx.Response(201, json={"id": "run-1"})
|
|
52
|
+
|
|
53
|
+
make_client(handler).investigate_ticket("t-1", run_type="triage", context_note="check gateway")
|
|
54
|
+
|
|
55
|
+
assert seen["method"] == "POST"
|
|
56
|
+
assert seen["path"] == "/api/v1/tickets/t-1/investigate"
|
|
57
|
+
assert seen["body"] == {"run_type": "triage", "context_note": "check gateway"}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_comment_defaults_to_internal():
|
|
61
|
+
seen = {}
|
|
62
|
+
|
|
63
|
+
def handler(request):
|
|
64
|
+
import json as _json
|
|
65
|
+
seen["body"] = _json.loads(request.content)
|
|
66
|
+
return httpx.Response(201, json={})
|
|
67
|
+
|
|
68
|
+
make_client(handler).comment_ticket("t-1", "looked at logs")
|
|
69
|
+
|
|
70
|
+
assert seen["body"]["is_internal"] is True
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_investigation_passes_run_id():
|
|
74
|
+
seen = {}
|
|
75
|
+
|
|
76
|
+
def handler(request):
|
|
77
|
+
seen["query"] = dict(request.url.params)
|
|
78
|
+
return httpx.Response(200, json={"run": {}})
|
|
79
|
+
|
|
80
|
+
make_client(handler).ticket_investigation("t-1", run_id="r-9")
|
|
81
|
+
|
|
82
|
+
assert seen["query"]["run_id"] == "r-9"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_update_settings_puts_payload():
|
|
86
|
+
seen = {}
|
|
87
|
+
|
|
88
|
+
def handler(request):
|
|
89
|
+
import json as _json
|
|
90
|
+
seen["method"] = request.method
|
|
91
|
+
seen["path"] = request.url.path
|
|
92
|
+
seen["body"] = _json.loads(request.content)
|
|
93
|
+
return httpx.Response(200, json={})
|
|
94
|
+
|
|
95
|
+
make_client(handler).update_ticket_settings({"autonomy_level": 2})
|
|
96
|
+
|
|
97
|
+
assert seen["method"] == "PUT"
|
|
98
|
+
assert seen["path"] == "/api/v1/tickets/settings"
|
|
99
|
+
assert seen["body"] == {"autonomy_level": 2}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# ---------- ticket reference resolution ----------
|
|
103
|
+
# Everyone reads "TKT-4"; the API wants the UUID. The CLI has to bridge that.
|
|
104
|
+
|
|
105
|
+
UUID_ONE = "c6575003-8472-4bba-88d4-6a414c392b1f"
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _search_client(items):
|
|
109
|
+
def handler(request):
|
|
110
|
+
return httpx.Response(200, json={"tickets": items, "pagination": {}})
|
|
111
|
+
return make_client(handler)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_resolves_ticket_number_to_uuid():
|
|
115
|
+
client = _search_client([{"id": UUID_ONE, "ticket_number": 4}])
|
|
116
|
+
assert _resolve_ticket_id(client, "TKT-4") == UUID_ONE
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_resolves_bare_number():
|
|
120
|
+
client = _search_client([{"id": UUID_ONE, "ticket_number": 4}])
|
|
121
|
+
assert _resolve_ticket_id(client, "4") == UUID_ONE
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_ignores_near_miss_numbers():
|
|
125
|
+
# search matches on digits, so 4 must not resolve to 44
|
|
126
|
+
client = _search_client([{"id": "other", "ticket_number": 44}])
|
|
127
|
+
with pytest.raises(typer.Exit):
|
|
128
|
+
_resolve_ticket_id(client, "TKT-4")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_uuid_passes_through_without_a_lookup():
|
|
132
|
+
def handler(request): # pragma: no cover - must never be called
|
|
133
|
+
raise AssertionError("should not hit the API for a UUID")
|
|
134
|
+
|
|
135
|
+
assert _resolve_ticket_id(make_client(handler), UUID_ONE) == UUID_ONE
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_unknown_reference_exits():
|
|
139
|
+
client = _search_client([])
|
|
140
|
+
with pytest.raises(typer.Exit):
|
|
141
|
+
_resolve_ticket_id(client, "TKT-999")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_reads_the_real_tickets_key_not_items():
|
|
145
|
+
# Regression: the API returns {"tickets": [...]}; an "items" assumption
|
|
146
|
+
# silently resolved nothing and made every lookup fail.
|
|
147
|
+
client = _search_client([{"id": UUID_ONE, "ticket_number": 4}])
|
|
148
|
+
assert _resolve_ticket_id(client, "TKT-4") == UUID_ONE
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_non_numeric_reference_exits_without_calling_the_api():
|
|
152
|
+
def handler(request): # pragma: no cover - must never be called
|
|
153
|
+
raise AssertionError("should not hit the API for a junk ref")
|
|
154
|
+
|
|
155
|
+
with pytest.raises(typer.Exit):
|
|
156
|
+
_resolve_ticket_id(make_client(handler), "not-a-ticket")
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def test_full_page_of_misses_reports_truncation():
|
|
160
|
+
# A common digit can fill the page via the title/description LIKE, so the
|
|
161
|
+
# number may genuinely not be on it — say so instead of "not found".
|
|
162
|
+
rows = [{"id": f"id-{i}", "ticket_number": 400 + i} for i in range(100)]
|
|
163
|
+
with pytest.raises(typer.Exit):
|
|
164
|
+
_resolve_ticket_id(_search_client(rows), "TKT-4")
|
|
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
|
{chattermate_cli-0.6.0 → chattermate_cli-0.8.0}/chattermate_cli.egg-info/dependency_links.txt
RENAMED
|
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
|