tinybird 0.0.1.dev255__py3-none-any.whl → 0.0.1.dev256__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.
Potentially problematic release.
This version of tinybird might be problematic. Click here for more details.
- tinybird/tb/__cli__.py +2 -2
- tinybird/tb/modules/agent/agent.py +35 -20
- tinybird/tb/modules/agent/memory.py +62 -0
- tinybird/tb/modules/agent/tools/deploy.py +0 -2
- tinybird/tb/modules/agent/tools/deploy_check.py +0 -3
- {tinybird-0.0.1.dev255.dist-info → tinybird-0.0.1.dev256.dist-info}/METADATA +1 -1
- {tinybird-0.0.1.dev255.dist-info → tinybird-0.0.1.dev256.dist-info}/RECORD +10 -10
- {tinybird-0.0.1.dev255.dist-info → tinybird-0.0.1.dev256.dist-info}/WHEEL +0 -0
- {tinybird-0.0.1.dev255.dist-info → tinybird-0.0.1.dev256.dist-info}/entry_points.txt +0 -0
- {tinybird-0.0.1.dev255.dist-info → tinybird-0.0.1.dev256.dist-info}/top_level.txt +0 -0
tinybird/tb/__cli__.py
CHANGED
|
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
|
|
|
4
4
|
__url__ = 'https://www.tinybird.co/docs/forward/commands'
|
|
5
5
|
__author__ = 'Tinybird'
|
|
6
6
|
__author_email__ = 'support@tinybird.co'
|
|
7
|
-
__version__ = '0.0.1.
|
|
8
|
-
__revision__ = '
|
|
7
|
+
__version__ = '0.0.1.dev256'
|
|
8
|
+
__revision__ = '78e1011'
|
|
@@ -26,7 +26,7 @@ from tinybird.prompts import (
|
|
|
26
26
|
from tinybird.tb.client import TinyB
|
|
27
27
|
from tinybird.tb.modules.agent.animations import ThinkingAnimation
|
|
28
28
|
from tinybird.tb.modules.agent.banner import display_banner
|
|
29
|
-
from tinybird.tb.modules.agent.memory import clear_history
|
|
29
|
+
from tinybird.tb.modules.agent.memory import clear_history, clear_messages, load_messages, save_messages
|
|
30
30
|
from tinybird.tb.modules.agent.models import create_model, model_costs
|
|
31
31
|
from tinybird.tb.modules.agent.prompts import (
|
|
32
32
|
datafile_instructions,
|
|
@@ -55,7 +55,7 @@ from tinybird.tb.modules.build_common import process as build_process
|
|
|
55
55
|
from tinybird.tb.modules.common import _analyze, _get_tb_client
|
|
56
56
|
from tinybird.tb.modules.config import CLIConfig
|
|
57
57
|
from tinybird.tb.modules.deployment_common import create_deployment
|
|
58
|
-
from tinybird.tb.modules.exceptions import CLIBuildException, CLIMockException
|
|
58
|
+
from tinybird.tb.modules.exceptions import CLIBuildException, CLIDeploymentException, CLIMockException
|
|
59
59
|
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
60
60
|
from tinybird.tb.modules.local_common import get_tinybird_local_client
|
|
61
61
|
from tinybird.tb.modules.login_common import login
|
|
@@ -78,7 +78,8 @@ class TinybirdAgent:
|
|
|
78
78
|
self.host = host
|
|
79
79
|
self.dangerously_skip_permissions = dangerously_skip_permissions
|
|
80
80
|
self.project = project
|
|
81
|
-
|
|
81
|
+
# we load the last 5 messages to manage token usage
|
|
82
|
+
self.messages: list[ModelMessage] = load_messages()[-5:]
|
|
82
83
|
self.agent = Agent(
|
|
83
84
|
model=create_model(user_token, host, workspace_id),
|
|
84
85
|
deps_type=TinybirdAgentContext,
|
|
@@ -186,13 +187,23 @@ Kafka: {kafka_connection_example}
|
|
|
186
187
|
S3: {s3_connection_example}
|
|
187
188
|
GCS: {gcs_connection_example}
|
|
188
189
|
|
|
189
|
-
# When executing a query or requesting an endpoint:
|
|
190
|
+
# When executing a query or requesting/testing an endpoint:
|
|
190
191
|
- You need to be sure that the selected resource is updated to the last version in the environment you are working on.
|
|
191
192
|
- Use `diff_resource` tool to compare the content of the resource to compare the differences between environments.
|
|
192
193
|
- Project local file is the source of truth.
|
|
193
194
|
- If the resource is not present or updated to the last version in Tinybird Local, it means you need to build the project.
|
|
194
195
|
- If the resource is not present or updated to the last version in Tinybird Cloud, it means you need to deploy the project.
|
|
195
196
|
|
|
197
|
+
# How to use apppend tools:
|
|
198
|
+
- Use append as part of the creation of a new landing datasource if the user provided a file or an external url
|
|
199
|
+
- Use append if user explicitly asks for it
|
|
200
|
+
- Do not append data if user requests to test an endpoint
|
|
201
|
+
|
|
202
|
+
# How to use `mock` tool:
|
|
203
|
+
- Use `mock` tool as part of the creation of a new landing datasource if the user did not provided a file or an external url
|
|
204
|
+
- Use `mock` tool if user explicitly asks for it
|
|
205
|
+
- Do not use `mock` tool if user requests to test an endpoint.
|
|
206
|
+
|
|
196
207
|
# Info
|
|
197
208
|
Today is {datetime.now().strftime("%Y-%m-%d")}
|
|
198
209
|
""",
|
|
@@ -268,6 +279,7 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
|
|
|
268
279
|
)
|
|
269
280
|
new_messages = result.new_messages()
|
|
270
281
|
self.messages.extend(new_messages)
|
|
282
|
+
save_messages(new_messages)
|
|
271
283
|
thinking_animation.stop()
|
|
272
284
|
usage = result.usage()
|
|
273
285
|
request_tokens = usage.request_tokens or 0
|
|
@@ -311,9 +323,12 @@ def run_agent(
|
|
|
311
323
|
login(host, auth_host="https://cloud.tinybird.co", workspace=None, interactive=False, method="browser")
|
|
312
324
|
click.echo()
|
|
313
325
|
cli_config = CLIConfig.get_project_config()
|
|
326
|
+
config = {**config, **cli_config.to_dict()}
|
|
314
327
|
token = cli_config.get_token()
|
|
315
328
|
user_token = cli_config.get_user_token()
|
|
316
329
|
host = cli_config.get_host()
|
|
330
|
+
workspace_id = cli_config.get("id", "")
|
|
331
|
+
workspace_name = cli_config.get("name", "")
|
|
317
332
|
|
|
318
333
|
if not token or not host or not user_token:
|
|
319
334
|
click.echo(
|
|
@@ -357,6 +372,7 @@ def run_agent(
|
|
|
357
372
|
break
|
|
358
373
|
elif user_input.lower() == "/clear":
|
|
359
374
|
clear_history()
|
|
375
|
+
clear_messages()
|
|
360
376
|
continue
|
|
361
377
|
elif user_input.lower() == "/login":
|
|
362
378
|
click.echo()
|
|
@@ -399,26 +415,25 @@ def build_project(config: dict[str, Any], project: Project, silent: bool = True,
|
|
|
399
415
|
|
|
400
416
|
def deploy_project(config: dict[str, Any], project: Project) -> None:
|
|
401
417
|
client = _get_tb_client(config["token"], config["host"])
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
418
|
+
try:
|
|
419
|
+
create_deployment(
|
|
420
|
+
project=project,
|
|
421
|
+
client=client,
|
|
422
|
+
config=config,
|
|
423
|
+
wait=True,
|
|
424
|
+
auto=True,
|
|
425
|
+
allow_destructive_operations=False,
|
|
426
|
+
)
|
|
427
|
+
except SystemExit as e:
|
|
428
|
+
raise CLIDeploymentException(e.args[0])
|
|
410
429
|
|
|
411
430
|
|
|
412
431
|
def deploy_check_project(config: dict[str, Any], project: Project) -> None:
|
|
413
432
|
client = _get_tb_client(config["token"], config["host"])
|
|
414
|
-
|
|
415
|
-
project=project,
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
check=True,
|
|
419
|
-
wait=True,
|
|
420
|
-
auto=True,
|
|
421
|
-
)
|
|
433
|
+
try:
|
|
434
|
+
create_deployment(project=project, client=client, config=config, check=True, wait=True, auto=True)
|
|
435
|
+
except SystemExit as e:
|
|
436
|
+
raise CLIDeploymentException(e.args[0])
|
|
422
437
|
|
|
423
438
|
|
|
424
439
|
def append_data(config: dict[str, Any], datasource_name: str, path: str) -> None:
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import json
|
|
1
2
|
from pathlib import Path
|
|
2
3
|
from typing import Optional
|
|
3
4
|
|
|
5
|
+
import click
|
|
4
6
|
from prompt_toolkit.history import FileHistory
|
|
7
|
+
from pydantic_ai.messages import ModelMessage, ModelMessagesTypeAdapter
|
|
8
|
+
from pydantic_core import to_jsonable_python
|
|
9
|
+
|
|
10
|
+
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
5
11
|
|
|
6
12
|
|
|
7
13
|
def get_history_file_path():
|
|
@@ -39,3 +45,59 @@ def clear_history():
|
|
|
39
45
|
"""Clear the history file"""
|
|
40
46
|
history_file = get_history_file_path()
|
|
41
47
|
history_file.unlink(missing_ok=True)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def clear_messages():
|
|
51
|
+
"""Clear the messages file"""
|
|
52
|
+
messages_file = get_messages_file_path()
|
|
53
|
+
messages_file.unlink(missing_ok=True)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get_messages_file_path():
|
|
57
|
+
"""Get the history file path based on current working directory"""
|
|
58
|
+
# Get current working directory
|
|
59
|
+
cwd = Path.cwd()
|
|
60
|
+
|
|
61
|
+
# Get user's home directory
|
|
62
|
+
home = Path.home()
|
|
63
|
+
|
|
64
|
+
# Calculate relative path from home to current directory
|
|
65
|
+
try:
|
|
66
|
+
relative_path = cwd.relative_to(home)
|
|
67
|
+
except ValueError:
|
|
68
|
+
# If current directory is not under home, use absolute path components
|
|
69
|
+
relative_path = Path(*cwd.parts[1:]) if cwd.is_absolute() else cwd
|
|
70
|
+
|
|
71
|
+
# Create history directory structure
|
|
72
|
+
history_dir = home / ".tinybird" / "projects" / relative_path
|
|
73
|
+
history_dir.mkdir(parents=True, exist_ok=True)
|
|
74
|
+
|
|
75
|
+
# Return history file path
|
|
76
|
+
return history_dir / "messages.json"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def load_messages() -> list[ModelMessage]:
|
|
80
|
+
try:
|
|
81
|
+
messages_file = get_messages_file_path()
|
|
82
|
+
messages_file.touch()
|
|
83
|
+
if not messages_file.exists():
|
|
84
|
+
messages_file.touch(exist_ok=True)
|
|
85
|
+
messages_file.write_text("[]")
|
|
86
|
+
return []
|
|
87
|
+
with open(messages_file, "r") as f:
|
|
88
|
+
messages_json = json.loads(f.read() or "[]")
|
|
89
|
+
return ModelMessagesTypeAdapter.validate_python(messages_json)
|
|
90
|
+
except Exception as e:
|
|
91
|
+
click.echo(FeedbackManager.error(message=f"Could not load previous messages: {e}"))
|
|
92
|
+
messages_file.unlink(missing_ok=True)
|
|
93
|
+
return []
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def save_messages(new_messages: list[ModelMessage]):
|
|
97
|
+
messages_file = get_messages_file_path()
|
|
98
|
+
messages_file.touch(exist_ok=True)
|
|
99
|
+
messages = load_messages()
|
|
100
|
+
messages.extend(new_messages)
|
|
101
|
+
messages_json = to_jsonable_python(messages)
|
|
102
|
+
with open(messages_file, "w") as f:
|
|
103
|
+
f.write(json.dumps(messages_json))
|
|
@@ -30,7 +30,5 @@ def deploy(ctx: RunContext[TinybirdAgentContext]) -> str:
|
|
|
30
30
|
ctx.deps.thinking_animation.start()
|
|
31
31
|
return "Project deployed successfully"
|
|
32
32
|
except Exception as e:
|
|
33
|
-
ctx.deps.thinking_animation.stop()
|
|
34
|
-
click.echo(FeedbackManager.error(message=e))
|
|
35
33
|
ctx.deps.thinking_animation.start()
|
|
36
34
|
return f"Error depoying project: {e}"
|
|
@@ -2,7 +2,6 @@ import click
|
|
|
2
2
|
from pydantic_ai import RunContext
|
|
3
3
|
|
|
4
4
|
from tinybird.tb.modules.agent.utils import TinybirdAgentContext, show_confirmation, show_input
|
|
5
|
-
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
def deploy_check(ctx: RunContext[TinybirdAgentContext]) -> str:
|
|
@@ -28,7 +27,5 @@ def deploy_check(ctx: RunContext[TinybirdAgentContext]) -> str:
|
|
|
28
27
|
ctx.deps.thinking_animation.start()
|
|
29
28
|
return "Project can be deployed"
|
|
30
29
|
except Exception as e:
|
|
31
|
-
ctx.deps.thinking_animation.stop()
|
|
32
|
-
click.echo(FeedbackManager.error(message=e))
|
|
33
30
|
ctx.deps.thinking_animation.start()
|
|
34
31
|
return f"Project cannot be deployed: {e}"
|
|
@@ -17,7 +17,7 @@ tinybird/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1w
|
|
|
17
17
|
tinybird/datafile/parse_connection.py,sha256=tRyn2Rpr1TeWet5BXmMoQgaotbGdYep1qiTak_OqC5E,1825
|
|
18
18
|
tinybird/datafile/parse_datasource.py,sha256=ssW8QeFSgglVFi3sDZj_HgkJiTJ2069v2JgqnH3CkDE,1825
|
|
19
19
|
tinybird/datafile/parse_pipe.py,sha256=xf4m0Tw44QWJzHzAm7Z7FwUoUUtr7noMYjU1NiWnX0k,3880
|
|
20
|
-
tinybird/tb/__cli__.py,sha256=
|
|
20
|
+
tinybird/tb/__cli__.py,sha256=BW9MQs4o1rm0FvIF2XLehXnuzpfC7A9JS2Fu2hJCJ2Y,247
|
|
21
21
|
tinybird/tb/check_pypi.py,sha256=Gp0HkHHDFMSDL6nxKlOY51z7z1Uv-2LRexNTZSHHGmM,552
|
|
22
22
|
tinybird/tb/cli.py,sha256=FdDFEIayjmsZEVsVSSvRiVYn_FHOVg_zWQzchnzfWho,1008
|
|
23
23
|
tinybird/tb/client.py,sha256=pJbdkWMXGAqKseNAvdsRRnl_c7I-DCMB0dWCQnG82nU,54146
|
|
@@ -68,10 +68,10 @@ tinybird/tb/modules/watch.py,sha256=No0bK1M1_3CYuMaIgylxf7vYFJ72lTJe3brz6xQ-mJo,
|
|
|
68
68
|
tinybird/tb/modules/workspace.py,sha256=Q_8HcxMsNg8QG9aBlwcWS2umrDP5IkTIHqqz3sfmGuc,11341
|
|
69
69
|
tinybird/tb/modules/workspace_members.py,sha256=5JdkJgfuEwbq-t6vxkBhYwgsiTDxF790wsa6Xfif9nk,8608
|
|
70
70
|
tinybird/tb/modules/agent/__init__.py,sha256=i3oe3vDIWWPaicdCM0zs7D7BJ1W0k7th93ooskHAV00,54
|
|
71
|
-
tinybird/tb/modules/agent/agent.py,sha256=
|
|
71
|
+
tinybird/tb/modules/agent/agent.py,sha256=mCQRrrheH7mEgRg6BF19lSLt2XzaD_mw6mhyugTQLyw,26412
|
|
72
72
|
tinybird/tb/modules/agent/animations.py,sha256=4WOC5_2BracttmMCrV0H91tXfWcUzQHBUaIJc5FA7tE,3490
|
|
73
73
|
tinybird/tb/modules/agent/banner.py,sha256=KX_e467uiy1gWOZ4ofTZt0GCFGQqHQ_8Ob27XLQqda0,3053
|
|
74
|
-
tinybird/tb/modules/agent/memory.py,sha256=
|
|
74
|
+
tinybird/tb/modules/agent/memory.py,sha256=O6Kumn9AyKxcTkhI45yjAUZ3ZIAibLOcNWoiEuLYeqY,3245
|
|
75
75
|
tinybird/tb/modules/agent/models.py,sha256=LW1D27gjcd_jwFmghEzteCgToDfodX2B6B5S8BYbysw,735
|
|
76
76
|
tinybird/tb/modules/agent/prompts.py,sha256=qyAv3H1x9qctlYQSel0DHxLlRJM2_8HTg7M-foSoR0k,17567
|
|
77
77
|
tinybird/tb/modules/agent/utils.py,sha256=5mUnc4LZATHLzQZThotNErzZdHQDwK3eur6W4NZULWA,26561
|
|
@@ -80,8 +80,8 @@ tinybird/tb/modules/agent/tools/analyze.py,sha256=7oxJ3waCS24Qja_k5GUB59_XiHTG9p
|
|
|
80
80
|
tinybird/tb/modules/agent/tools/append.py,sha256=ekG7OxOzPjjjAjYUONAfp_PWlzyLT1GDfQhECgO-DYY,5065
|
|
81
81
|
tinybird/tb/modules/agent/tools/build.py,sha256=LhzJMx6tbxC7gogIrxhfKJc-SDgoSR-FC6IunfaCdn8,758
|
|
82
82
|
tinybird/tb/modules/agent/tools/create_datafile.py,sha256=wcPcChACTIFKw0lKFTlhm0sWJKhQkMLPLnGNpKyeETA,2962
|
|
83
|
-
tinybird/tb/modules/agent/tools/deploy.py,sha256=
|
|
84
|
-
tinybird/tb/modules/agent/tools/deploy_check.py,sha256=
|
|
83
|
+
tinybird/tb/modules/agent/tools/deploy.py,sha256=dxNmzz8vCLIPNrfwyzof74gJK5cF-GfKHUfQ1vEX4hg,1347
|
|
84
|
+
tinybird/tb/modules/agent/tools/deploy_check.py,sha256=9roUI7FOvhNXbvi1iilS1RNYso4-WsNDVR9m7rmeOy4,1170
|
|
85
85
|
tinybird/tb/modules/agent/tools/diff_resource.py,sha256=euKo_mD9FZHC1X6yESv3D_CXMzBMB8EWHLeZjIRqjJg,2637
|
|
86
86
|
tinybird/tb/modules/agent/tools/execute_query.py,sha256=hMRahWZkyP9qa-nMGzY0Z7MjDa9sb5O9V1evmA_V_w8,2702
|
|
87
87
|
tinybird/tb/modules/agent/tools/explore.py,sha256=ihALc_kBcsjrKT3hZyicqyIowB0g_K3AtNNi-5uz9-8,412
|
|
@@ -111,8 +111,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
|
|
|
111
111
|
tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
|
|
112
112
|
tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
|
|
113
113
|
tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
|
|
114
|
-
tinybird-0.0.1.
|
|
115
|
-
tinybird-0.0.1.
|
|
116
|
-
tinybird-0.0.1.
|
|
117
|
-
tinybird-0.0.1.
|
|
118
|
-
tinybird-0.0.1.
|
|
114
|
+
tinybird-0.0.1.dev256.dist-info/METADATA,sha256=QFATRwPa6QPBUcV7rO4TwGvOBOyt5Dd2VmFjlnFUdV0,1733
|
|
115
|
+
tinybird-0.0.1.dev256.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
116
|
+
tinybird-0.0.1.dev256.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
|
|
117
|
+
tinybird-0.0.1.dev256.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
|
|
118
|
+
tinybird-0.0.1.dev256.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|