tokenjam 0.2.0__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.
- tokenjam/__init__.py +1 -0
- tokenjam/api/__init__.py +0 -0
- tokenjam/api/app.py +104 -0
- tokenjam/api/deps.py +18 -0
- tokenjam/api/middleware.py +28 -0
- tokenjam/api/routes/__init__.py +0 -0
- tokenjam/api/routes/agents.py +33 -0
- tokenjam/api/routes/alerts.py +77 -0
- tokenjam/api/routes/budget.py +96 -0
- tokenjam/api/routes/cost.py +43 -0
- tokenjam/api/routes/drift.py +63 -0
- tokenjam/api/routes/logs.py +511 -0
- tokenjam/api/routes/metrics.py +81 -0
- tokenjam/api/routes/otlp.py +63 -0
- tokenjam/api/routes/spans.py +202 -0
- tokenjam/api/routes/status.py +84 -0
- tokenjam/api/routes/tools.py +22 -0
- tokenjam/api/routes/traces.py +92 -0
- tokenjam/cli/__init__.py +0 -0
- tokenjam/cli/cmd_alerts.py +94 -0
- tokenjam/cli/cmd_budget.py +119 -0
- tokenjam/cli/cmd_cost.py +90 -0
- tokenjam/cli/cmd_demo.py +82 -0
- tokenjam/cli/cmd_doctor.py +173 -0
- tokenjam/cli/cmd_drift.py +238 -0
- tokenjam/cli/cmd_export.py +200 -0
- tokenjam/cli/cmd_mcp.py +78 -0
- tokenjam/cli/cmd_onboard.py +779 -0
- tokenjam/cli/cmd_serve.py +85 -0
- tokenjam/cli/cmd_status.py +153 -0
- tokenjam/cli/cmd_stop.py +87 -0
- tokenjam/cli/cmd_tools.py +45 -0
- tokenjam/cli/cmd_traces.py +161 -0
- tokenjam/cli/cmd_uninstall.py +159 -0
- tokenjam/cli/main.py +110 -0
- tokenjam/core/__init__.py +0 -0
- tokenjam/core/alerts.py +619 -0
- tokenjam/core/api_backend.py +235 -0
- tokenjam/core/config.py +360 -0
- tokenjam/core/cost.py +102 -0
- tokenjam/core/db.py +718 -0
- tokenjam/core/drift.py +256 -0
- tokenjam/core/ingest.py +265 -0
- tokenjam/core/models.py +225 -0
- tokenjam/core/pricing.py +54 -0
- tokenjam/core/retention.py +21 -0
- tokenjam/core/schema_validator.py +156 -0
- tokenjam/demo/__init__.py +0 -0
- tokenjam/demo/env.py +96 -0
- tokenjam/mcp/__init__.py +0 -0
- tokenjam/mcp/server.py +1067 -0
- tokenjam/otel/__init__.py +0 -0
- tokenjam/otel/exporters.py +26 -0
- tokenjam/otel/provider.py +207 -0
- tokenjam/otel/semconv.py +144 -0
- tokenjam/pricing/models.toml +70 -0
- tokenjam/py.typed +0 -0
- tokenjam/sdk/__init__.py +21 -0
- tokenjam/sdk/agent.py +206 -0
- tokenjam/sdk/bootstrap.py +120 -0
- tokenjam/sdk/http_exporter.py +109 -0
- tokenjam/sdk/integrations/__init__.py +0 -0
- tokenjam/sdk/integrations/anthropic.py +200 -0
- tokenjam/sdk/integrations/autogen.py +97 -0
- tokenjam/sdk/integrations/base.py +27 -0
- tokenjam/sdk/integrations/bedrock.py +103 -0
- tokenjam/sdk/integrations/crewai.py +96 -0
- tokenjam/sdk/integrations/gemini.py +131 -0
- tokenjam/sdk/integrations/langchain.py +156 -0
- tokenjam/sdk/integrations/langgraph.py +101 -0
- tokenjam/sdk/integrations/litellm.py +323 -0
- tokenjam/sdk/integrations/llamaindex.py +52 -0
- tokenjam/sdk/integrations/nemoclaw.py +139 -0
- tokenjam/sdk/integrations/openai.py +159 -0
- tokenjam/sdk/integrations/openai_agents_sdk.py +47 -0
- tokenjam/sdk/transport.py +98 -0
- tokenjam/ui/index.html +1213 -0
- tokenjam/utils/__init__.py +0 -0
- tokenjam/utils/formatting.py +43 -0
- tokenjam/utils/ids.py +15 -0
- tokenjam/utils/time_parse.py +54 -0
- tokenjam-0.2.0.dist-info/METADATA +622 -0
- tokenjam-0.2.0.dist-info/RECORD +86 -0
- tokenjam-0.2.0.dist-info/WHEEL +4 -0
- tokenjam-0.2.0.dist-info/entry_points.txt +2 -0
- tokenjam-0.2.0.dist-info/licenses/LICENSE +21 -0
tokenjam/cli/main.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import click
|
|
2
|
+
from tokenjam.core.config import load_config
|
|
3
|
+
from tokenjam.core.db import open_db
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@click.group()
|
|
7
|
+
@click.version_option(package_name="tokenjam")
|
|
8
|
+
@click.option("--config", "config_path", default=None, envvar="TJ_CONFIG",
|
|
9
|
+
help="Config file path (default: auto-discover)")
|
|
10
|
+
@click.option("--json", "output_json", is_flag=True,
|
|
11
|
+
help="Output machine-readable JSON")
|
|
12
|
+
@click.option("--no-color", is_flag=True)
|
|
13
|
+
@click.option("--db", "db_path", default=None, help="Database path override")
|
|
14
|
+
@click.option("--agent", default=None, help="Filter to specific agent_id")
|
|
15
|
+
@click.option("-v", "--verbose", is_flag=True)
|
|
16
|
+
@click.pass_context
|
|
17
|
+
def cli(ctx: click.Context, config_path: str | None, output_json: bool,
|
|
18
|
+
no_color: bool, db_path: str | None, agent: str | None,
|
|
19
|
+
verbose: bool) -> None:
|
|
20
|
+
"""tj - local-first observability for AI agents."""
|
|
21
|
+
ctx.ensure_object(dict)
|
|
22
|
+
config = load_config(config_path)
|
|
23
|
+
if db_path:
|
|
24
|
+
config.storage.path = db_path
|
|
25
|
+
|
|
26
|
+
# Commands that don't need a database connection
|
|
27
|
+
no_db_commands = {"stop", "uninstall", "onboard", "mcp", "demo"}
|
|
28
|
+
invoked = ctx.invoked_subcommand
|
|
29
|
+
if invoked in no_db_commands:
|
|
30
|
+
ctx.obj["config"] = config
|
|
31
|
+
ctx.obj["db"] = None
|
|
32
|
+
ctx.obj["output_json"] = output_json
|
|
33
|
+
ctx.obj["no_color"] = no_color
|
|
34
|
+
ctx.obj["agent"] = agent
|
|
35
|
+
ctx.obj["verbose"] = verbose
|
|
36
|
+
if no_color:
|
|
37
|
+
from rich import reconfigure
|
|
38
|
+
reconfigure(no_color=True)
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
db = None
|
|
42
|
+
try:
|
|
43
|
+
db = open_db(config.storage)
|
|
44
|
+
except Exception as e:
|
|
45
|
+
err_msg = str(e).lower()
|
|
46
|
+
if "lock" in err_msg or "already open" in err_msg or "i/o error" in err_msg:
|
|
47
|
+
from tokenjam.core.api_backend import probe_api
|
|
48
|
+
api_key = config.api.auth.api_key if config.api.auth.enabled else None
|
|
49
|
+
db = probe_api(config.api.host, config.api.port, api_key)
|
|
50
|
+
if db is None:
|
|
51
|
+
raise click.ClickException(
|
|
52
|
+
"Database is locked (tj serve is running?) and the API "
|
|
53
|
+
f"is not reachable at http://{config.api.host}:{config.api.port}. "
|
|
54
|
+
"Start tj serve or stop the process holding the DB lock."
|
|
55
|
+
) from e
|
|
56
|
+
ctx.obj["api_mode"] = True
|
|
57
|
+
else:
|
|
58
|
+
raise
|
|
59
|
+
|
|
60
|
+
ctx.obj["config"] = config
|
|
61
|
+
ctx.obj["db"] = db
|
|
62
|
+
ctx.obj["output_json"] = output_json
|
|
63
|
+
ctx.obj["no_color"] = no_color
|
|
64
|
+
ctx.obj["agent"] = agent
|
|
65
|
+
ctx.obj["verbose"] = verbose
|
|
66
|
+
if no_color:
|
|
67
|
+
from rich import reconfigure
|
|
68
|
+
reconfigure(no_color=True)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# Register all subcommands
|
|
72
|
+
from tokenjam.cli.cmd_onboard import cmd_onboard # noqa: E402
|
|
73
|
+
from tokenjam.cli.cmd_status import cmd_status # noqa: E402
|
|
74
|
+
from tokenjam.cli.cmd_traces import cmd_traces, cmd_trace # noqa: E402
|
|
75
|
+
from tokenjam.cli.cmd_cost import cmd_cost # noqa: E402
|
|
76
|
+
from tokenjam.cli.cmd_alerts import cmd_alerts # noqa: E402
|
|
77
|
+
from tokenjam.cli.cmd_tools import cmd_tools # noqa: E402
|
|
78
|
+
from tokenjam.cli.cmd_export import cmd_export # noqa: E402
|
|
79
|
+
from tokenjam.cli.cmd_serve import cmd_serve # noqa: E402
|
|
80
|
+
from tokenjam.cli.cmd_stop import cmd_stop # noqa: E402
|
|
81
|
+
from tokenjam.cli.cmd_uninstall import cmd_uninstall # noqa: E402
|
|
82
|
+
from tokenjam.cli.cmd_doctor import cmd_doctor # noqa: E402
|
|
83
|
+
from tokenjam.cli.cmd_budget import cmd_budget # noqa: E402
|
|
84
|
+
|
|
85
|
+
cli.add_command(cmd_onboard, name="onboard")
|
|
86
|
+
cli.add_command(cmd_status, name="status")
|
|
87
|
+
cli.add_command(cmd_traces, name="traces")
|
|
88
|
+
cli.add_command(cmd_trace, name="trace")
|
|
89
|
+
cli.add_command(cmd_cost, name="cost")
|
|
90
|
+
cli.add_command(cmd_alerts, name="alerts")
|
|
91
|
+
cli.add_command(cmd_tools, name="tools")
|
|
92
|
+
cli.add_command(cmd_export, name="export")
|
|
93
|
+
cli.add_command(cmd_serve, name="serve")
|
|
94
|
+
cli.add_command(cmd_stop, name="stop")
|
|
95
|
+
cli.add_command(cmd_uninstall, name="uninstall")
|
|
96
|
+
cli.add_command(cmd_doctor, name="doctor")
|
|
97
|
+
cli.add_command(cmd_budget, name="budget")
|
|
98
|
+
|
|
99
|
+
# cmd_drift is provided by task 05 — register if available
|
|
100
|
+
try:
|
|
101
|
+
from tokenjam.cli.cmd_drift import cmd_drift # noqa: E402
|
|
102
|
+
cli.add_command(cmd_drift, name="drift")
|
|
103
|
+
except ImportError:
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
from tokenjam.cli.cmd_mcp import cmd_mcp # noqa: E402
|
|
107
|
+
cli.add_command(cmd_mcp, name="mcp")
|
|
108
|
+
|
|
109
|
+
from tokenjam.cli.cmd_demo import cmd_demo # noqa: E402
|
|
110
|
+
cli.add_command(cmd_demo, name="demo")
|
|
File without changes
|