cometapi-cli 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

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.
cometapi_cli/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """CometAPI CLI — professional terminal interface for CometAPI."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.2.2"
@@ -7,28 +7,50 @@ from typing import Annotated
7
7
  import typer
8
8
 
9
9
  from ..config import get_client
10
+ from ..console import err_console
10
11
  from ..errors import handle_errors
11
12
  from ..formatters import OutputFormat, output, resolve_format
12
13
 
14
+ BALANCE_SOURCE_ALIASES = {
15
+ "account": "account",
16
+ "key": "key",
17
+ "token": "key",
18
+ }
19
+
20
+
21
+ def _normalize_balance_source(source: str | None) -> str | None:
22
+ if source is None:
23
+ return None
24
+
25
+ normalized = BALANCE_SOURCE_ALIASES.get(source.lower())
26
+ if normalized is not None:
27
+ return normalized
28
+
29
+ err_console.print(f"[red]Invalid source:[/] {source}. Valid sources: account, key")
30
+ raise typer.Exit(code=2)
31
+
13
32
 
14
33
  @handle_errors
15
34
  def balance(
16
35
  ctx: typer.Context,
17
36
  source: Annotated[
18
37
  str | None,
19
- typer.Option("--source", "-s", help="Data source: 'account' (full account) or 'token' (current API key)."),
38
+ typer.Option("--source", "-s", help="Data source: 'account' (full account) or 'key' (current API key)."),
39
+ ] = None,
40
+ output_format: Annotated[
41
+ OutputFormat | None,
42
+ typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown)."),
20
43
  ] = None,
21
- output_format: Annotated[OutputFormat | None, typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown).")] = None,
22
44
  json_output: Annotated[bool, typer.Option("--json", help="Output as JSON.")] = False,
23
45
  ) -> None:
24
46
  """Show your CometAPI account balance.
25
47
 
26
48
  By default shows account-level balance (requires access token), falling back
27
- to per-token billing stats. Use --source to force a specific view.
49
+ to per-key billing stats. Use --source to force a specific view.
28
50
  """
29
51
  fmt = resolve_format(ctx, json_output, output_format)
30
52
  client = get_client()
31
- raw = client.get_balance(source=source)
53
+ raw = client.get_balance(source=_normalize_balance_source(source))
32
54
 
33
55
  # For JSON output, pass raw data for maximum information
34
56
  if fmt == OutputFormat.JSON:
@@ -2,6 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import re
6
+ from functools import cmp_to_key
5
7
  from typing import Annotated
6
8
 
7
9
  import typer
@@ -10,13 +12,63 @@ from ..config import get_client
10
12
  from ..errors import handle_errors
11
13
  from ..formatters import OutputFormat, output, resolve_format
12
14
 
15
+ _MODEL_TOKEN_RE = re.compile(r"[a-z]+|\d+")
16
+
17
+
18
+ def _tokenize_model_id(model_id: str) -> list[str | int]:
19
+ tokens: list[str | int] = []
20
+ for segment in re.split(r"[-.]+", model_id.lower()):
21
+ if not segment:
22
+ continue
23
+ for part in _MODEL_TOKEN_RE.findall(segment):
24
+ tokens.append(int(part) if part.isdigit() else part)
25
+ return tokens
26
+
27
+
28
+ def _compare_model_ids(left: str, right: str) -> int:
29
+ left_tokens = _tokenize_model_id(left)
30
+ right_tokens = _tokenize_model_id(right)
31
+
32
+ for left_token, right_token in zip(left_tokens, right_tokens):
33
+ if left_token == right_token:
34
+ continue
35
+
36
+ if isinstance(left_token, int) and isinstance(right_token, int):
37
+ return -1 if left_token > right_token else 1
38
+
39
+ if isinstance(left_token, int):
40
+ return -1
41
+ if isinstance(right_token, int):
42
+ return 1
43
+
44
+ return -1 if left_token > right_token else 1
45
+
46
+ if len(left_tokens) == len(right_tokens):
47
+ if left.lower() == right.lower():
48
+ return 0
49
+ return -1 if left.lower() > right.lower() else 1
50
+
51
+ if len(left_tokens) < len(right_tokens):
52
+ next_token = right_tokens[len(left_tokens)]
53
+ return 1 if isinstance(next_token, int) else -1
54
+
55
+ next_token = left_tokens[len(right_tokens)]
56
+ return -1 if isinstance(next_token, int) else 1
57
+
58
+
59
+ def _compare_model_rows(left: dict[str, str], right: dict[str, str]) -> int:
60
+ return _compare_model_ids(left["id"], right["id"])
61
+
13
62
 
14
63
  @handle_errors
15
64
  def models(
16
65
  ctx: typer.Context,
17
66
  search: Annotated[str | None, typer.Option("--search", "-s", help="Filter models by name.")] = None,
18
67
  limit: Annotated[int | None, typer.Option("--limit", "-l", help="Max number of models to show.")] = None,
19
- output_format: Annotated[OutputFormat | None, typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown).")] = None,
68
+ output_format: Annotated[
69
+ OutputFormat | None,
70
+ typer.Option("--format", "-f", help="Output format (table, json, yaml, csv, markdown)."),
71
+ ] = None,
20
72
  json_output: Annotated[bool, typer.Option("--json", help="Output as JSON.")] = False,
21
73
  ) -> None:
22
74
  """List available models."""
@@ -24,15 +76,14 @@ def models(
24
76
  client = get_client()
25
77
  result = client.models.list()
26
78
 
27
- rows = sorted(
28
- [{"id": m.id, "owned_by": m.owned_by} for m in result],
29
- key=lambda r: r["id"],
30
- )
79
+ rows = [{"id": m.id} for m in result]
31
80
 
32
81
  if search:
33
82
  term = search.lower()
34
83
  rows = [r for r in rows if term in r["id"].lower()]
35
84
 
85
+ rows = sorted(rows, key=cmp_to_key(_compare_model_rows))
86
+
36
87
  if limit and limit > 0:
37
88
  rows = rows[:limit]
38
89
 
@@ -40,5 +91,5 @@ def models(
40
91
  rows,
41
92
  fmt,
42
93
  title=f"Available Models ({len(rows)})",
43
- columns={"id": "cyan", "owned_by": "green"},
94
+ columns={"id": "cyan"},
44
95
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cometapi-cli
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: CometAPI CLI — official command-line interface for the CometAPI AI gateway
5
5
  Project-URL: Homepage, https://github.com/cometapi-dev/cometapi-cli
6
6
  Project-URL: Repository, https://github.com/cometapi-dev/cometapi-cli
@@ -42,7 +42,7 @@ Description-Content-Type: text/markdown
42
42
  [![Python](https://img.shields.io/pypi/pyversions/cometapi-cli)](https://pypi.org/project/cometapi-cli/)
43
43
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
44
44
 
45
- > **Official command-line interface for [CometAPI](https://cometapi.com)** — 500+ AI Model API, All In One API.
45
+ > **Official command-line interface for [CometAPI](https://www.cometapi.com/?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=homepage)** — 500+ AI Model API, All In One API.
46
46
 
47
47
  Access 500+ AI models at low cost, directly from the terminal. Chat, search models, check usage, and manage your account — all through a single API key.
48
48
 
@@ -59,7 +59,7 @@ pipx install cometapi-cli # isolated environment
59
59
  uv tool install cometapi-cli # uv
60
60
  ```
61
61
 
62
- **Prerequisites**: Python 3.10+ · [Get your API key](https://www.cometapi.com/console/token)
62
+ **Prerequisites**: Python 3.10+ · [CometAPI Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=prerequisites)
63
63
 
64
64
  ## Quick Start
65
65
 
@@ -77,8 +77,8 @@ cometapi models --search gpt --limit 10
77
77
  Or configure manually:
78
78
 
79
79
  ```bash
80
- export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token
81
- export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal (optional)
80
+ export COMETAPI_KEY="your-api-key" # https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-api-key
81
+ export COMETAPI_ACCESS_TOKEN="your-access-token" # https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=env-access-token (optional)
82
82
  ```
83
83
 
84
84
  ## Commands
@@ -226,7 +226,7 @@ pytest -v
226
226
  - API keys and access tokens are **never** logged or displayed in full — only the last 4 characters are shown
227
227
  - Config files are stored with restrictive permissions (`0600`)
228
228
  - Credentials should **never** be committed to version control
229
- - Create credentials at: [API Key](https://www.cometapi.com/console/token) · [Access Token](https://www.cometapi.com/console/personal)
229
+ - Create credentials at: [API Key](https://www.cometapi.com/console/token?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-api-key) · [Access Token](https://www.cometapi.com/console/personal?utm_source=cometapi-cli&utm_medium=readme&utm_campaign=oss&utm_content=security-access-token)
230
230
  - **Disclaimer**: You are responsible for all usage and charges incurred with your API keys
231
231
 
232
232
  ## Troubleshooting
@@ -244,7 +244,3 @@ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines
244
244
  ## License
245
245
 
246
246
  This project is licensed under the [MIT License](LICENSE).
247
-
248
- ## License
249
-
250
- MIT
@@ -1,4 +1,4 @@
1
- cometapi_cli/__init__.py,sha256=bzbn6erL2EJHZufQyz5Vv_9VOwVD8K54C2ZgpQX7oBQ,92
1
+ cometapi_cli/__init__.py,sha256=YoHkL8RaBOgm8zi4mJO3F2ywNNSkk26kuGB8cjLLRrE,92
2
2
  cometapi_cli/app.py,sha256=tFrkyfVVBYkjOA9zXP72bZ1csHI9HBnGF-Z4_4EkXkE,2784
3
3
  cometapi_cli/client.py,sha256=4JkMSrjWwAQV8tmlwplZQ75gzt3zHno8ASKLgMCpYkU,9658
4
4
  cometapi_cli/config.py,sha256=oJXQidKCOsKNYPnE8OfLLoOfsv0MSZEDICB6VShJRSA,3307
@@ -9,19 +9,19 @@ cometapi_cli/formatters.py,sha256=QrXpsQHRYiJ49Rwz_7dOMoKxCcnRPumZMrxH21ZQaMw,45
9
9
  cometapi_cli/main.py,sha256=4NmO8MAAc_H30hahT6VNrdGdlaFlQ99AixKcRV5iDXE,168
10
10
  cometapi_cli/commands/__init__.py,sha256=mihzLmD4ADkH9WnCBP2p1fn95lU3GyzTliAJ1XL5Ngg,29
11
11
  cometapi_cli/commands/account.py,sha256=yGIY5iQeB4j1bISMUOqnvjcuD9HTd7VcWSvSFB6fAfo,1257
12
- cometapi_cli/commands/balance.py,sha256=GUOdbfDV0u9h23XG3pqRf_tl3mUxWGl781b9eep4Rxc,1833
12
+ cometapi_cli/commands/balance.py,sha256=BT96WTt2I7dCLBlAkZMX4KYliqC5C7QCXKNWCbXwldw,2353
13
13
  cometapi_cli/commands/chat.py,sha256=5VuNOF7O3vjD0f8eD0faZ3xL2IFnSa2BNadxencoPJk,3937
14
14
  cometapi_cli/commands/chat_repl.py,sha256=b9lkYnbbaOb0AlSpRcq3wWHmnhtTXvaqeJiUImsMEBY,8176
15
15
  cometapi_cli/commands/config_cmd.py,sha256=JU4ZS8ur2Sq1MjMZKaGLaI1TdM3CAUDE45qsKDOxD_8,8528
16
16
  cometapi_cli/commands/doctor.py,sha256=EPcezrf64yzgYrzOdp_7tvfNM6hE2NBDzgMgO-O0Dnw,5337
17
17
  cometapi_cli/commands/logs.py,sha256=9J7oT9KbCCGeD_zO9fwWj7g5QjaoT8qqJF_e81jGPX4,10310
18
- cometapi_cli/commands/models.py,sha256=kW8rJHfzymW28ZR_RA1Oi1z0Sh-p9KeSNR7gdfDo6VE,1332
18
+ cometapi_cli/commands/models.py,sha256=wtnZp0RqUE6HH2ZsZr6OYtHDwzUPIOcJBBxXWKOQ-Ig,2875
19
19
  cometapi_cli/commands/repl.py,sha256=b5z1jmEXOsCrb6fwEUyv-IKot929NIPQQAbA1uas1D4,4283
20
20
  cometapi_cli/commands/stats.py,sha256=6ULBb7rX5Q0yWuIxtYLataNPoJ_SkU3Y4RovgdVyROs,1388
21
21
  cometapi_cli/commands/tasks.py,sha256=TW_Jgli7iyfIoHNyufbViAUMIieMNfsD8DMHt5mQA8Q,4625
22
22
  cometapi_cli/commands/tokens.py,sha256=9KHer9MQOZvm_Ybxnhjb5_TtGgKyv3MtI5lqsHy-Qxg,3019
23
- cometapi_cli-0.2.0.dist-info/METADATA,sha256=t3nT4TDZvKlNPCJfEpmyDqScunDm2glcPGH0srjergI,8123
24
- cometapi_cli-0.2.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
25
- cometapi_cli-0.2.0.dist-info/entry_points.txt,sha256=xoiE2ZVNNWXTq0JRBtzC8hJ2JkdKuaBNz_fEd8OJpLs,50
26
- cometapi_cli-0.2.0.dist-info/licenses/LICENSE,sha256=-rBwHQzkmLbty07abmGvQvsRrvDeEQUkPDhNJfTcjdE,1065
27
- cometapi_cli-0.2.0.dist-info/RECORD,,
23
+ cometapi_cli-0.2.2.dist-info/METADATA,sha256=Aveuc9r_GBg70ue7jZL4j1P6hkyFKTKruBQXa3kCk48,8624
24
+ cometapi_cli-0.2.2.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
25
+ cometapi_cli-0.2.2.dist-info/entry_points.txt,sha256=xoiE2ZVNNWXTq0JRBtzC8hJ2JkdKuaBNz_fEd8OJpLs,50
26
+ cometapi_cli-0.2.2.dist-info/licenses/LICENSE,sha256=-rBwHQzkmLbty07abmGvQvsRrvDeEQUkPDhNJfTcjdE,1065
27
+ cometapi_cli-0.2.2.dist-info/RECORD,,