tinybird 0.0.1.dev289__py3-none-any.whl → 0.0.1.dev290__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 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.dev289'
8
- __revision__ = 'ac20837'
7
+ __version__ = '0.0.1.dev290'
8
+ __revision__ = '4d1cca4'
@@ -23,6 +23,7 @@ from tinybird.tb.modules.agent.banner import display_banner
23
23
  from tinybird.tb.modules.agent.command_agent import CommandAgent
24
24
  from tinybird.tb.modules.agent.compactor import compact_messages
25
25
  from tinybird.tb.modules.agent.explore_agent import ExploreAgent
26
+ from tinybird.tb.modules.agent.file_agent import FileAgent
26
27
  from tinybird.tb.modules.agent.memory import (
27
28
  clear_history,
28
29
  clear_messages,
@@ -185,6 +186,16 @@ class TinybirdAgent:
185
186
  workspace_id=workspace_id,
186
187
  project=self.project,
187
188
  )
189
+ self.file_agent = FileAgent(
190
+ dangerously_skip_permissions=self.dangerously_skip_permissions,
191
+ prompt_mode=prompt_mode,
192
+ thinking_animation=self.thinking_animation,
193
+ token=self.token,
194
+ user_token=self.user_token,
195
+ host=self.host,
196
+ workspace_id=workspace_id,
197
+ project=self.project,
198
+ )
188
199
 
189
200
  @self.agent.tool
190
201
  def manage_tests(ctx: RunContext[TinybirdAgentContext], task: str) -> str:
@@ -251,6 +262,19 @@ class TinybirdAgent:
251
262
  result = self.mock_agent.run(user_input, deps=ctx.deps, usage=ctx.usage)
252
263
  return result.output or "No result returned"
253
264
 
265
+ @self.agent.tool
266
+ def manage_files(ctx: RunContext[TinybirdAgentContext], task: str) -> str:
267
+ """List file/folders and read any type of file in the current directory. Use this tool when you need to list or read non Tinybird project files (e.g. .txt, .md).
268
+
269
+ Args:
270
+ task (str): The task to solve. Required.
271
+
272
+ Returns:
273
+ str: The result of the task.
274
+ """
275
+ result = self.file_agent.run(task, deps=ctx.deps, usage=ctx.usage)
276
+ return result.output or "No result returned"
277
+
254
278
  @self.agent.instructions
255
279
  def get_local_host(ctx: RunContext[TinybirdAgentContext]) -> str:
256
280
  return f"""
@@ -0,0 +1,64 @@
1
+ from pydantic_ai import Agent, Tool
2
+ from pydantic_ai.messages import ModelMessage
3
+ from pydantic_ai.usage import Usage
4
+
5
+ from tinybird.tb.modules.agent.animations import ThinkingAnimation
6
+ from tinybird.tb.modules.agent.models import create_model
7
+ from tinybird.tb.modules.agent.prompts import tone_and_style_instructions
8
+ from tinybird.tb.modules.agent.tools.file import list_files, read_file
9
+ from tinybird.tb.modules.agent.utils import TinybirdAgentContext
10
+ from tinybird.tb.modules.project import Project
11
+
12
+
13
+ class FileAgent:
14
+ def __init__(
15
+ self,
16
+ token: str,
17
+ user_token: str,
18
+ host: str,
19
+ workspace_id: str,
20
+ project: Project,
21
+ dangerously_skip_permissions: bool,
22
+ prompt_mode: bool,
23
+ thinking_animation: ThinkingAnimation,
24
+ ):
25
+ self.token = token
26
+ self.user_token = user_token
27
+ self.host = host
28
+ self.workspace_id = workspace_id
29
+ self.dangerously_skip_permissions = dangerously_skip_permissions or prompt_mode
30
+ self.project = project
31
+ self.thinking_animation = thinking_animation
32
+ self.messages: list[ModelMessage] = []
33
+ self.agent = Agent(
34
+ model=create_model(user_token, host, workspace_id),
35
+ deps_type=TinybirdAgentContext,
36
+ instructions=[
37
+ """
38
+ You are part of Tinybird Code, an agentic CLI that can help users to work with Tinybird.
39
+ You are a sub-agent of the main Tinybird Code agent. You are responsible for managing files.
40
+ You can do the following:
41
+ - List files in a directory.
42
+ - Read a file.
43
+
44
+ IMPORTANT: Use the `list_files` tool always before `read_file` to get the correct file path.
45
+ """,
46
+ tone_and_style_instructions,
47
+ ],
48
+ tools=[
49
+ Tool(list_files, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
50
+ Tool(read_file, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
51
+ ],
52
+ )
53
+
54
+ def run(self, task: str, deps: TinybirdAgentContext, usage: Usage):
55
+ result = self.agent.run_sync(
56
+ task,
57
+ deps=deps,
58
+ usage=usage,
59
+ message_history=self.messages,
60
+ model=create_model(self.user_token, self.host, self.workspace_id, run_id=deps.run_id),
61
+ )
62
+ new_messages = result.new_messages()
63
+ self.messages.extend(new_messages)
64
+ return result
@@ -24,7 +24,7 @@ def append_file(
24
24
  Args:
25
25
  datasource_name: Name of the datasource to append fixture to
26
26
  fixture_pathname: Path to the fixture file to append
27
- cloud: Whether to append the fixture to the cloud or local environment. If None (user didn't specify), will ask user to clarify. Defaults to local (False) in dangerous skip permissions mode.
27
+ cloud: Whether to append the fixture to the cloud or local environment. If None (user didn't specify in a previous step), will ask user to clarify. Defaults to local (False) in dangerous skip permissions mode.
28
28
 
29
29
  Returns:
30
30
  str: Message indicating the success or failure of the appending
@@ -54,6 +54,7 @@ def append_file(
54
54
 
55
55
  cloud_or_local = "Cloud" if cloud else "Local"
56
56
  active_plan = ctx.deps.get_plan() is not None and not cloud
57
+ ctx.deps.thinking_animation.stop()
57
58
  confirmation = show_confirmation(
58
59
  title=f"Append fixture {fixture_pathname} to datasource '{datasource_name}' in Tinybird {cloud_or_local}?",
59
60
  skip_confirmation=ctx.deps.dangerously_skip_permissions or active_plan,
@@ -0,0 +1,82 @@
1
+ from glob import glob
2
+ from pathlib import Path
3
+
4
+ import click
5
+ from pydantic_ai import RunContext
6
+
7
+ from tinybird.tb.modules.agent.utils import TinybirdAgentContext
8
+ from tinybird.tb.modules.feedback_manager import FeedbackManager
9
+
10
+
11
+ def list_files(
12
+ ctx: RunContext[TinybirdAgentContext],
13
+ folder_path: str = ".",
14
+ search_pattern: str = "*",
15
+ ) -> str:
16
+ """Lists all files and folders in a directory.
17
+
18
+ Args:
19
+ folder_path (str): The path to the directory to list. If not provided, it will list the files in the current directory. Default: "."
20
+ search_pattern (str): The pattern to search for in the files and folders. Default: "*"
21
+ Returns:
22
+ str: The list of files in the directory.
23
+ """
24
+ try:
25
+ ctx.deps.thinking_animation.stop()
26
+ if folder_path:
27
+ path = Path(folder_path)
28
+ else:
29
+ path = Path.cwd()
30
+
31
+ display_folder = "current directory" if (folder_path == "." or not folder_path) else folder_path
32
+
33
+ click.echo(
34
+ FeedbackManager.highlight(message=f"» Searching in {display_folder} with pattern '{search_pattern}'")
35
+ )
36
+
37
+ if not path.exists():
38
+ ctx.deps.thinking_animation.start()
39
+ return f"Folder {folder_path} does not exist"
40
+
41
+ result = glob(f"{path}/**/{search_pattern}", recursive=True)
42
+ folders = [f for f in result if Path(f).is_dir()]
43
+ files = [f for f in result if Path(f).is_file()]
44
+
45
+ ctx.deps.thinking_animation.start()
46
+ return f"Folders: {folders}\nFiles: {files}"
47
+ except Exception as e:
48
+ ctx.deps.thinking_animation.start()
49
+ return f"Error listing files: {e}"
50
+
51
+
52
+ def read_file(ctx: RunContext[TinybirdAgentContext], file_path: str) -> str:
53
+ """Reads a file from the local filesystem. The file_path parameter must be an absolute path, not a relative path. Any lines longer than 2000 characters will be truncated.
54
+
55
+ Args:
56
+ file_path (str): The path to the file to read.
57
+
58
+ Returns:
59
+ str: The content of the file.
60
+ """
61
+ try:
62
+ ctx.deps.thinking_animation.stop()
63
+ click.echo(FeedbackManager.highlight(message=f"» Reading file {file_path}"))
64
+ path = Path(file_path)
65
+
66
+ if not path.exists():
67
+ ctx.deps.thinking_animation.start()
68
+ return f"File {file_path} does not exist"
69
+
70
+ content = path.read_text()
71
+ chunks = content.split("\n")
72
+
73
+ if len(chunks) > 2000:
74
+ first_2000 = "\n".join(chunks[0:2000])
75
+ ctx.deps.thinking_animation.start()
76
+ return f"This file is too large to be read by the agent. Showing first 2000 lines instead:\n\n{first_2000}"
77
+
78
+ ctx.deps.thinking_animation.start()
79
+ return content
80
+ except Exception as e:
81
+ ctx.deps.thinking_animation.start()
82
+ return f"Error reading file: {e}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev289
3
+ Version: 0.0.1.dev290
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -18,7 +18,7 @@ tinybird/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1w
18
18
  tinybird/datafile/parse_connection.py,sha256=tRyn2Rpr1TeWet5BXmMoQgaotbGdYep1qiTak_OqC5E,1825
19
19
  tinybird/datafile/parse_datasource.py,sha256=ssW8QeFSgglVFi3sDZj_HgkJiTJ2069v2JgqnH3CkDE,1825
20
20
  tinybird/datafile/parse_pipe.py,sha256=xf4m0Tw44QWJzHzAm7Z7FwUoUUtr7noMYjU1NiWnX0k,3880
21
- tinybird/tb/__cli__.py,sha256=mQDawLTa-oQDyZZZYyjnBrWWRtaViQL0ZaN2lmv4e1E,247
21
+ tinybird/tb/__cli__.py,sha256=OrSAyOixAYmHAPopJr6x4hd9XD_ZWyUyoEWSDwnX-ZI,247
22
22
  tinybird/tb/check_pypi.py,sha256=Gp0HkHHDFMSDL6nxKlOY51z7z1Uv-2LRexNTZSHHGmM,552
23
23
  tinybird/tb/cli.py,sha256=FdDFEIayjmsZEVsVSSvRiVYn_FHOVg_zWQzchnzfWho,1008
24
24
  tinybird/tb/client.py,sha256=IQRaInDjOwr9Fzaz3_xXc3aUGqh94tM2lew7IZbB9eM,53733
@@ -70,12 +70,13 @@ tinybird/tb/modules/watch.py,sha256=No0bK1M1_3CYuMaIgylxf7vYFJ72lTJe3brz6xQ-mJo,
70
70
  tinybird/tb/modules/workspace.py,sha256=tCP1zZMwBhLRGm22TGfpSd4cHvQLAS1o_azIXv_r6uw,11172
71
71
  tinybird/tb/modules/workspace_members.py,sha256=5JdkJgfuEwbq-t6vxkBhYwgsiTDxF790wsa6Xfif9nk,8608
72
72
  tinybird/tb/modules/agent/__init__.py,sha256=i3oe3vDIWWPaicdCM0zs7D7BJ1W0k7th93ooskHAV00,54
73
- tinybird/tb/modules/agent/agent.py,sha256=wxLG84pYfNdQPB1TI6Nkv_8Y_bO5lmOX3ht87gnmrwY,36315
73
+ tinybird/tb/modules/agent/agent.py,sha256=uVZ0yGOk4uRtF74mPHIYjawIDPSCweb5HCC7eLVuf2k,37339
74
74
  tinybird/tb/modules/agent/animations.py,sha256=4WOC5_2BracttmMCrV0H91tXfWcUzQHBUaIJc5FA7tE,3490
75
75
  tinybird/tb/modules/agent/banner.py,sha256=l6cO5Fi7lbVKp-GsBP8jf3IkjOWxg2jpAt9NBCy0WR8,4085
76
76
  tinybird/tb/modules/agent/command_agent.py,sha256=0Z08rQsir59zQAr-kkOvsKIFpIBsBSTGJJ1VgqqF5WA,3654
77
77
  tinybird/tb/modules/agent/compactor.py,sha256=BK5AxZFhrp3xWnsRnYaleiYoIWtVNc-_m650Hsopt8g,13841
78
78
  tinybird/tb/modules/agent/explore_agent.py,sha256=gyD5uV5TJwV24eeQiSwhkgfNPb4mtbeH7t2qSdoc18U,4100
79
+ tinybird/tb/modules/agent/file_agent.py,sha256=vE8VChVbG_-uyeBtp3I6QrXeNaPaVlVoNn4c9cGTAJA,2466
79
80
  tinybird/tb/modules/agent/memory.py,sha256=vBewB_64L_wHoT4tLT6UX2uxcHwSY880QZ26F9rPqXs,3793
80
81
  tinybird/tb/modules/agent/mock_agent.py,sha256=zbAZfAqdSLUtMr2VqO0erWpzjT2F1tTcuYjvHb-gvbA,8023
81
82
  tinybird/tb/modules/agent/models.py,sha256=eokO8XlY-kVJOsbqiVporGUAOCyKAXCO5xgTEK9SM6Y,2208
@@ -84,13 +85,14 @@ tinybird/tb/modules/agent/testing_agent.py,sha256=AtwtJViH7805i7djyBgDb7SSUtDyJn
84
85
  tinybird/tb/modules/agent/utils.py,sha256=alvRNtpPPRZP0sNdOXbzX3uQZHqqeh1daIAg3aquq24,32015
85
86
  tinybird/tb/modules/agent/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
86
87
  tinybird/tb/modules/agent/tools/analyze.py,sha256=CR5LXg4fou-zYEksqnjpJ0icvxJVoKnTctoI1NRvqCM,3873
87
- tinybird/tb/modules/agent/tools/append.py,sha256=8UsGMzmv7GYbzp0gerOBqpxxocDbous_haSuwS3zuGU,8222
88
+ tinybird/tb/modules/agent/tools/append.py,sha256=cF-1XYmgTXI3dfMQ_nEpOKo6duJGe2GOg64rXNnS9gw,8284
88
89
  tinybird/tb/modules/agent/tools/build.py,sha256=Hm-xDAP9ckMiKquT-DmDg5H0yxZefLOaWKANyoVSaEQ,846
89
90
  tinybird/tb/modules/agent/tools/datafile.py,sha256=kTob7G2TwCwIgwom0rERgXQ13rgPtZv3_ByLnrvpIdU,10881
90
91
  tinybird/tb/modules/agent/tools/deploy.py,sha256=6Vmm0lCG8XKE2iUF_ZJrOqXbTFhoe3anPzYCFehQ3_E,2027
91
92
  tinybird/tb/modules/agent/tools/deploy_check.py,sha256=pE3d9TPtXVKZjYbU0G6ORAGI86lN5K_4JKUriClERbM,1229
92
93
  tinybird/tb/modules/agent/tools/diff_resource.py,sha256=_9xHcDzCTKk_E1wKQbuktVqV6U9sA0kqYaBxWvtliX0,2613
93
94
  tinybird/tb/modules/agent/tools/execute_query.py,sha256=DL2jsZ0jaEqFIkGoiWfR-IUAwsgoF0D-_JUhq7xe4gA,9145
95
+ tinybird/tb/modules/agent/tools/file.py,sha256=_strhF1bnFFui3pVGUi2dFdcKzMyYzOD59lKeSHqG7o,2855
94
96
  tinybird/tb/modules/agent/tools/get_endpoint_stats.py,sha256=r2FrXg1L1s_Llr1tPdJ6k_gu6qw7qLsAXOkbz3eTk1g,2307
95
97
  tinybird/tb/modules/agent/tools/get_openapi_definition.py,sha256=4TIMO2XzHBMhpt9zIWRfjjPZbThT8r_iPS4CVHcItE0,2904
96
98
  tinybird/tb/modules/agent/tools/mock.py,sha256=Seo4WcYNLL1-SmPXutoaX94_pfOdIb47JXo8dHtUVhg,7106
@@ -119,8 +121,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
119
121
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
120
122
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
121
123
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
122
- tinybird-0.0.1.dev289.dist-info/METADATA,sha256=ENjdQSJQH3QgYbGGAJddSYazWCBQ-ZJbpW6SyEqFGKE,1845
123
- tinybird-0.0.1.dev289.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
124
- tinybird-0.0.1.dev289.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
125
- tinybird-0.0.1.dev289.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
126
- tinybird-0.0.1.dev289.dist-info/RECORD,,
124
+ tinybird-0.0.1.dev290.dist-info/METADATA,sha256=rgJDi-VYXwLLOeFrK9n1nONEYic69YtTXbVcxDFW0yU,1845
125
+ tinybird-0.0.1.dev290.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
126
+ tinybird-0.0.1.dev290.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
127
+ tinybird-0.0.1.dev290.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
128
+ tinybird-0.0.1.dev290.dist-info/RECORD,,