chattermate-cli 0.8.0__tar.gz → 0.8.1__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.
Files changed (40) hide show
  1. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/PKG-INFO +1 -1
  2. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/__init__.py +1 -1
  3. chattermate_cli-0.8.1/chattermate_cli/agent_env.py +42 -0
  4. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/client.py +5 -1
  5. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/auth.py +14 -1
  6. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/widget.py +26 -3
  7. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli.egg-info/PKG-INFO +1 -1
  8. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli.egg-info/SOURCES.txt +2 -0
  9. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/pyproject.toml +1 -1
  10. chattermate_cli-0.8.1/tests/test_signup_attribution.py +114 -0
  11. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_widget.py +17 -0
  12. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/LICENSE +0 -0
  13. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/README.md +0 -0
  14. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/__init__.py +0 -0
  15. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/agent.py +0 -0
  16. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/ai.py +0 -0
  17. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/customization.py +0 -0
  18. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/help_center.py +0 -0
  19. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/knowledge.py +0 -0
  20. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/lead_capture.py +0 -0
  21. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/ticketing.py +0 -0
  22. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/commands/workflow.py +0 -0
  23. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/config.py +0 -0
  24. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/context.py +0 -0
  25. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/main.py +0 -0
  26. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli/mcp_server.py +0 -0
  27. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli.egg-info/dependency_links.txt +0 -0
  28. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli.egg-info/entry_points.txt +0 -0
  29. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli.egg-info/requires.txt +0 -0
  30. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/chattermate_cli.egg-info/top_level.txt +0 -0
  31. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/setup.cfg +0 -0
  32. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_ai.py +0 -0
  33. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_auth.py +0 -0
  34. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_client.py +0 -0
  35. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_customization.py +0 -0
  36. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_help_center.py +0 -0
  37. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_knowledge.py +0 -0
  38. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_lead_capture.py +0 -0
  39. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_mcp.py +0 -0
  40. {chattermate_cli-0.8.0 → chattermate_cli-0.8.1}/tests/test_ticketing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chattermate-cli
3
- Version: 0.8.0
3
+ Version: 0.8.1
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
@@ -16,4 +16,4 @@ You should have received a copy of the GNU Affero General Public License
16
16
  along with this program. If not, see <https://www.gnu.org/licenses/>
17
17
  """
18
18
 
19
- __version__ = "0.8.0"
19
+ __version__ = "0.8.1"
@@ -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
@@ -175,14 +175,18 @@ class Client:
175
175
  def signup_verify_otp(
176
176
  self, email: str, otp: str, admin_name: str, admin_password: str,
177
177
  organization_name: str, domain: str, colorcode: Optional[str] = None,
178
+ attribution: Optional[Dict[str, str]] = None,
178
179
  ) -> Dict[str, Any]:
179
- """Enterprise signup step 2: verify OTP and create the org + admin."""
180
+ """Enterprise signup step 2: verify OTP and create the org + admin.
181
+ `attribution` says where the signup came from (client, ref, agent)."""
180
182
  body = {
181
183
  "email": email, "otp": otp, "name": admin_name, "password": admin_password,
182
184
  "organization_name": organization_name, "domain": domain,
183
185
  }
184
186
  if colorcode:
185
187
  body["colorcode"] = colorcode
188
+ if attribution:
189
+ body["attribution"] = attribution
186
190
  data = self.request("POST", "/enterprise/signup/verify-otp", json=body, auth=False)
187
191
  if isinstance(data, dict) and data.get("access_token"):
188
192
  self.token = data.get("access_token")
@@ -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:
@@ -16,18 +16,41 @@ You should have received a copy of the GNU Affero General Public License
16
16
  along with this program. If not, see <https://www.gnu.org/licenses/>
17
17
  """
18
18
 
19
+ from typing import Optional
20
+
19
21
  import typer
20
22
  from rich.table import Table
21
23
 
24
+ from ..client import API_PREFIX
22
25
  from ..context import console, get_client, output, run
23
26
 
27
+ # The cloud dashboard, which serves the widget loader
28
+ CLOUD_APP_URL = "https://app.chattermate.chat"
29
+
24
30
  widget_app = typer.Typer(no_args_is_help=True, help="Manage embeddable chat widgets.")
25
31
 
26
32
 
33
+ def embed_snippet(widget_id: str, api_url: str, app_url: Optional[str] = None) -> str:
34
+ """The embed code the dashboard shows: the widget id, the API it talks to,
35
+ and the loader from the dashboard that serves it (the cloud's by default)."""
36
+ loader_origin = (app_url or CLOUD_APP_URL).rstrip("/")
37
+ return "\n".join([
38
+ "<script>",
39
+ f" window.chattermateId = '{widget_id}';",
40
+ f" window.chattermateBaseUrl = '{api_url.rstrip('/')}{API_PREFIX}';",
41
+ "</script>",
42
+ f'<script src="{loader_origin}/webclient/chattermate.min.js"></script>',
43
+ ])
44
+
45
+
27
46
  @widget_app.command("create")
28
47
  def create_widget(
29
48
  agent_id: str = typer.Option(..., "--agent-id", help="Agent to attach the widget to."),
30
49
  name: str = typer.Option("Website widget", "--name", help="Widget name."),
50
+ app_url: Optional[str] = typer.Option(
51
+ None, "--app-url",
52
+ help="Where your ChatterMate dashboard runs, on a self-hosted install (it serves the widget loader).",
53
+ ),
31
54
  as_json: bool = typer.Option(False, "--json", help="Output raw JSON."),
32
55
  ):
33
56
  """Create an embeddable widget for an agent and print its widget id + embed snippet."""
@@ -38,9 +61,9 @@ def create_widget(
38
61
  return
39
62
  widget_id = data.get("id") if isinstance(data, dict) else None
40
63
  console.print(f"[green]Created widget[/green] {widget_id}")
41
- console.print("Embed it on your site:")
42
- console.print(f" <script>window.chattermateId='{widget_id}';</script>")
43
- console.print(' <script src="https://app.chattermate.chat/webclient/chattermate.min.js"></script>')
64
+ console.print("Embed it on your site, just before </body>:")
65
+ # Plain echo: rich would wrap long lines and read [...] as markup
66
+ typer.echo(embed_snippet(widget_id, client.api_url, app_url))
44
67
 
45
68
 
46
69
  @widget_app.command("list")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chattermate-cli
3
- Version: 0.8.0
3
+ Version: 0.8.1
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
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
4
  chattermate_cli/__init__.py
5
+ chattermate_cli/agent_env.py
5
6
  chattermate_cli/client.py
6
7
  chattermate_cli/config.py
7
8
  chattermate_cli/context.py
@@ -32,5 +33,6 @@ tests/test_help_center.py
32
33
  tests/test_knowledge.py
33
34
  tests/test_lead_capture.py
34
35
  tests/test_mcp.py
36
+ tests/test_signup_attribution.py
35
37
  tests/test_ticketing.py
36
38
  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.8.0"
7
+ version = "0.8.1"
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,114 @@
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
+ A CLI signup tells the API where it came from: the CLI and its version,
19
+ the --ref it was given and the AI coding tool running it.
20
+ """
21
+
22
+ import json
23
+
24
+ import httpx
25
+ from typer.testing import CliRunner
26
+
27
+ from chattermate_cli import __version__
28
+ from chattermate_cli.agent_env import AGENT_ENV_VARS, detect_agent
29
+ from chattermate_cli.client import Client
30
+ from chattermate_cli.commands import auth
31
+ from chattermate_cli.main import app
32
+
33
+
34
+ def make_client(handler):
35
+ client = Client(api_url="http://test")
36
+ client._http = httpx.Client(transport=httpx.MockTransport(handler))
37
+ return client
38
+
39
+
40
+ def test_detects_each_coding_tool():
41
+ for var, name in AGENT_ENV_VARS.items():
42
+ assert detect_agent({var: "1"}) == name
43
+
44
+
45
+ def test_no_coding_tool():
46
+ assert detect_agent({}) is None
47
+ assert detect_agent({"CLAUDECODE": ""}) is None
48
+
49
+
50
+ def test_verify_otp_sends_attribution():
51
+ sent = {}
52
+
53
+ def handler(request):
54
+ sent.update(json.loads(request.content))
55
+ return httpx.Response(200, json={"access_token": "a", "refresh_token": "r"})
56
+
57
+ make_client(handler).signup_verify_otp(
58
+ email="o@acme.com", otp="123456", admin_name="Owner", admin_password="pw",
59
+ organization_name="Acme", domain="acme.com",
60
+ attribution={"client": "cli/0.8.0", "ref": "website-ai-prompt"},
61
+ )
62
+ assert sent["attribution"] == {"client": "cli/0.8.0", "ref": "website-ai-prompt"}
63
+
64
+
65
+ def test_verify_otp_without_attribution_sends_none():
66
+ sent = {}
67
+
68
+ def handler(request):
69
+ sent.update(json.loads(request.content))
70
+ return httpx.Response(200, json={})
71
+
72
+ make_client(handler).signup_verify_otp(
73
+ email="o@acme.com", otp="123456", admin_name="Owner", admin_password="pw",
74
+ organization_name="Acme", domain="acme.com",
75
+ )
76
+ assert "attribution" not in sent
77
+
78
+
79
+ def test_attribution_for_a_signup(monkeypatch):
80
+ for var in AGENT_ENV_VARS:
81
+ monkeypatch.delenv(var, raising=False)
82
+ assert auth.signup_attribution(None) == {"client": f"cli/{__version__}"}
83
+
84
+ monkeypatch.setenv("CLAUDECODE", "1")
85
+ assert auth.signup_attribution("website-ai-prompt") == {
86
+ "client": f"cli/{__version__}", "ref": "website-ai-prompt", "agent": "claude-code",
87
+ }
88
+
89
+
90
+ def test_signup_command_passes_ref_and_tool(monkeypatch, tmp_path):
91
+ monkeypatch.setenv("HOME", str(tmp_path))
92
+ monkeypatch.setenv("CURSOR_TRACE_ID", "trace")
93
+ for var in AGENT_ENV_VARS:
94
+ if var != "CURSOR_TRACE_ID":
95
+ monkeypatch.delenv(var, raising=False)
96
+ calls = {}
97
+
98
+ class FakeClient:
99
+ token = None
100
+
101
+ def signup_verify_otp(self, **kwargs):
102
+ calls.update(kwargs)
103
+ return {}
104
+
105
+ monkeypatch.setattr(auth, "get_client", lambda require_auth=False: FakeClient())
106
+ result = CliRunner().invoke(app, [
107
+ "signup", "--name", "Acme", "--domain", "acme.com", "--admin-email", "o@acme.com",
108
+ "--admin-name", "Owner", "--admin-password", "Secret123!", "--otp", "123456",
109
+ "--ref", "signup-ai-prompt",
110
+ ])
111
+ assert result.exit_code == 0, result.output
112
+ assert calls["attribution"] == {
113
+ "client": f"cli/{__version__}", "ref": "signup-ai-prompt", "agent": "cursor",
114
+ }
@@ -51,3 +51,20 @@ def test_list_widgets_for_agent_gets_by_agent():
51
51
 
52
52
  assert seen["path"] == "/api/v1/widgets/agent/ag-1"
53
53
  assert rows[0]["id"] == "w-1"
54
+
55
+
56
+ def test_embed_snippet_on_the_cloud():
57
+ from chattermate_cli.commands.widget import embed_snippet
58
+
59
+ snippet = embed_snippet("w-1", "https://api.chattermate.chat")
60
+ assert "window.chattermateId = 'w-1';" in snippet
61
+ assert "window.chattermateBaseUrl = 'https://api.chattermate.chat/api/v1';" in snippet
62
+ assert '<script src="https://app.chattermate.chat/webclient/chattermate.min.js"></script>' in snippet
63
+
64
+
65
+ def test_embed_snippet_on_a_self_hosted_install():
66
+ from chattermate_cli.commands.widget import embed_snippet
67
+
68
+ snippet = embed_snippet("w-1", "https://support.acme.com/", app_url="https://chat.acme.com/")
69
+ assert "window.chattermateBaseUrl = 'https://support.acme.com/api/v1';" in snippet
70
+ assert '<script src="https://chat.acme.com/webclient/chattermate.min.js"></script>' in snippet
File without changes