tinybird 0.0.1.dev240__py3-none-any.whl → 0.0.1.dev242__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.dev240'
8
- __revision__ = '268407c'
7
+ __version__ = '0.0.1.dev242'
8
+ __revision__ = '62ad714'
@@ -21,8 +21,9 @@ from tinybird.prompts import (
21
21
  s3_connection_example,
22
22
  sink_pipe_instructions,
23
23
  )
24
+ from tinybird.tb.client import TinyB
25
+ from tinybird.tb.modules.agent.animations import ThinkingAnimation
24
26
  from tinybird.tb.modules.agent.banner import display_banner
25
- from tinybird.tb.modules.agent.client import TinybirdClient
26
27
  from tinybird.tb.modules.agent.memory import clear_history, load_history
27
28
  from tinybird.tb.modules.agent.models import create_model
28
29
  from tinybird.tb.modules.agent.prompts import datafile_instructions, plan_instructions, sql_instructions
@@ -125,7 +126,7 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
125
126
  Tool(explore_data, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
126
127
  Tool(preview_datafile, docstring_format="google", require_parameter_descriptions=True, takes_ctx=False),
127
128
  Tool(create_datafile, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
128
- Tool(plan, docstring_format="google", require_parameter_descriptions=True, takes_ctx=False),
129
+ Tool(plan, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
129
130
  ],
130
131
  )
131
132
 
@@ -134,17 +135,25 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
134
135
  return self.messages[-5:] if len(self.messages) > 5 else self.messages
135
136
 
136
137
  def run(self, user_prompt: str) -> None:
138
+ client = TinyB(token=self.token, host=self.host)
139
+
140
+ thinking_animation = ThinkingAnimation(message="Chirping", delay=0.15)
141
+ thinking_animation.start()
142
+
137
143
  result = self.agent.run_sync(
138
144
  user_prompt,
139
145
  deps=TinybirdAgentContext(
140
- client=TinybirdClient(token=self.token, host=self.host),
146
+ # context does not support the whole client, so we need to pass only the functions we need
147
+ explore_data=client.explore_data,
141
148
  folder=self.folder,
149
+ thinking_animation=thinking_animation,
142
150
  ),
143
151
  message_history=self.messages,
144
152
  )
145
153
  new_messages = result.new_messages()
146
154
  self.messages.extend(new_messages)
147
- click.echo("\n")
155
+ thinking_animation.stop()
156
+
148
157
  click.echo(result.output)
149
158
  click.echo("\n")
150
159
 
@@ -0,0 +1,86 @@
1
+ import random
2
+ import sys
3
+ import threading
4
+ from time import sleep
5
+ from typing import Optional
6
+
7
+ import click
8
+
9
+
10
+ class ThinkingAnimation:
11
+ """Thinking animation that shows changing sparkles as a prefix."""
12
+
13
+ def __init__(
14
+ self,
15
+ message: str = "Thinking",
16
+ delay: float = 0.15,
17
+ colors: bool = True,
18
+ dots: bool = True,
19
+ ):
20
+ self.message = message
21
+ self.delay = delay
22
+ self.running = False
23
+ self.thread: Optional[threading.Thread] = None
24
+ self.colors = colors and sys.stdout.isatty()
25
+ self.dots = dots
26
+
27
+ # Default sparkle characters
28
+ self.sparkle_chars = ["✧", "✦", "⋆", "✳", "✺", "✹", "*", "·"]
29
+
30
+ # ANSI color codes
31
+ self.colors_list = [
32
+ "\033[33m", # Yellow
33
+ "\033[36m", # Cyan
34
+ "\033[35m", # Magenta
35
+ "\033[93m", # Bright Yellow
36
+ "\033[96m", # Bright Cyan
37
+ ]
38
+ self.reset_color = "\033[0m"
39
+
40
+ def start(self):
41
+ """Start the animation in a separate thread."""
42
+ self.running = True
43
+ self.thread = threading.Thread(target=self._run_animation)
44
+ self.thread.daemon = True
45
+
46
+ click.echo("\n")
47
+ self.thread.start()
48
+
49
+ def stop(self):
50
+ """Stop the animation."""
51
+ self.running = False
52
+ if self.thread:
53
+ self.thread.join()
54
+ # Clear the line and reset cursor position
55
+ sys.stdout.write("\r" + " " * (len(self.message) + 10) + "\r")
56
+ sys.stdout.flush()
57
+
58
+ def _run_animation(self):
59
+ """Run the animation until stopped."""
60
+ frame_count = 0
61
+ dots_count = 0
62
+
63
+ while self.running:
64
+ # Choose a random sparkle for this frame
65
+ sparkle = random.choice(self.sparkle_chars)
66
+
67
+ if self.colors:
68
+ color = random.choice(self.colors_list)
69
+ colored_sparkle = f"{color}{sparkle}{self.reset_color}"
70
+ else:
71
+ colored_sparkle = sparkle
72
+
73
+ # Handle dots animation if enabled
74
+ if self.dots:
75
+ dots_count = (frame_count // 4) % 4 # Change dots every 4 frames
76
+ dots = "." * dots_count
77
+ display_message = f"{self.message}{dots}"
78
+ else:
79
+ display_message = self.message
80
+
81
+ # Print the message with the prefix sparkle
82
+ sys.stdout.write(f"\r{colored_sparkle} {display_message}")
83
+ sys.stdout.flush()
84
+
85
+ sleep(self.delay)
86
+ frame_count += 1
@@ -6,7 +6,7 @@ from pydantic_ai.providers.anthropic import AnthropicProvider
6
6
 
7
7
  def create_model(
8
8
  token: str,
9
- base_url: str = "https://api.wadus3.aws.tinybird.co",
9
+ base_url: str,
10
10
  model: AnthropicModelName = "claude-4-sonnet-20250514",
11
11
  ):
12
12
  client = AsyncAnthropic(
@@ -35,9 +35,11 @@ def create_datafile(ctx: RunContext[TinybirdAgentContext], resource: Datafile) -
35
35
  str: If the resource was created or not.
36
36
  """
37
37
  try:
38
+ ctx.deps.thinking_animation.stop()
38
39
  click.echo()
39
40
  click.echo(resource.content)
40
41
  confirmation = get_resource_confirmation(resource)
42
+ ctx.deps.thinking_animation.start()
41
43
 
42
44
  if not confirmation:
43
45
  return f"Resource {resource.pathname} was not created. User cancelled creation."
@@ -12,4 +12,4 @@ def explore_data(ctx: RunContext[TinybirdAgentContext], prompt: str):
12
12
  Returns:
13
13
  str: The result of the exploration.
14
14
  """
15
- return ctx.deps.client.explore_data(prompt)
15
+ return ctx.deps.explore_data(prompt)
@@ -1,6 +1,7 @@
1
1
  import click
2
+ from pydantic_ai import RunContext
2
3
 
3
- from tinybird.tb.modules.agent.utils import show_options
4
+ from tinybird.tb.modules.agent.utils import TinybirdAgentContext, show_options
4
5
 
5
6
 
6
7
  def get_plan_confirmation() -> bool:
@@ -22,7 +23,7 @@ def get_plan_confirmation() -> bool:
22
23
  return False
23
24
 
24
25
 
25
- def plan(plan: str) -> str:
26
+ def plan(ctx: RunContext[TinybirdAgentContext], plan: str) -> str:
26
27
  """Given a plan, ask the user for confirmation to implement it
27
28
 
28
29
  Args:
@@ -32,9 +33,11 @@ def plan(plan: str) -> str:
32
33
  str: If the plan was implemented or not.
33
34
  """
34
35
  try:
36
+ ctx.deps.thinking_animation.stop()
35
37
  click.echo()
36
38
  click.echo(plan)
37
39
  confirmation = get_plan_confirmation()
40
+ ctx.deps.thinking_animation.start()
38
41
 
39
42
  if not confirmation:
40
43
  return "Plan was not implemented. User cancelled implementation."
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  from contextlib import contextmanager
3
- from typing import Any, List, Optional
3
+ from typing import Any, Callable, List, Optional
4
4
 
5
5
  import click
6
6
  from prompt_toolkit.application import Application, get_app
@@ -16,12 +16,11 @@ from prompt_toolkit.shortcuts import PromptSession
16
16
  from prompt_toolkit.styles import Style
17
17
  from pydantic import BaseModel, Field
18
18
 
19
- from tinybird.tb.modules.agent.client import TinybirdClient
20
-
21
19
 
22
20
  class TinybirdAgentContext(BaseModel):
23
- client: TinybirdClient
21
+ explore_data: Callable[[str], str]
24
22
  folder: str
23
+ thinking_animation: Any
25
24
 
26
25
 
27
26
  default_style = Style.from_dict(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev240
3
+ Version: 0.0.1.dev242
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -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=OB0M6HqPur6rsd93Mf9BRpLf5zvrZ_aq4HvYd7nAacc,247
20
+ tinybird/tb/__cli__.py,sha256=WaMYFAckfNWnMzyIA-CatGh7AXWIKDHBGMB-QqtF2rw,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
@@ -63,17 +63,17 @@ tinybird/tb/modules/watch.py,sha256=No0bK1M1_3CYuMaIgylxf7vYFJ72lTJe3brz6xQ-mJo,
63
63
  tinybird/tb/modules/workspace.py,sha256=Q_8HcxMsNg8QG9aBlwcWS2umrDP5IkTIHqqz3sfmGuc,11341
64
64
  tinybird/tb/modules/workspace_members.py,sha256=5JdkJgfuEwbq-t6vxkBhYwgsiTDxF790wsa6Xfif9nk,8608
65
65
  tinybird/tb/modules/agent/__init__.py,sha256=i3oe3vDIWWPaicdCM0zs7D7BJ1W0k7th93ooskHAV00,54
66
- tinybird/tb/modules/agent/agent.py,sha256=98X8rqUszArhOnrWWGAJRNwAK-me6Ql2UGNGFxcuc2E,10205
66
+ tinybird/tb/modules/agent/agent.py,sha256=TWHU9gEPH7EZQguno1P_HZ5jO7v6QLj9UE1btgaAOxg,10570
67
+ tinybird/tb/modules/agent/animations.py,sha256=z0MNLf8TnUO8qAjgYvth_wc9a9283pNVz1Z4jl15Ggs,2558
67
68
  tinybird/tb/modules/agent/banner.py,sha256=KX_e467uiy1gWOZ4ofTZt0GCFGQqHQ_8Ob27XLQqda0,3053
68
- tinybird/tb/modules/agent/client.py,sha256=ZNE_0xtbrfhXXRZ7nx3Ze0gHb1IK7zXRLTlGudAAuUg,1264
69
69
  tinybird/tb/modules/agent/memory.py,sha256=H6SJK--2L5C87B7AJd_jMqsq3sCvFvZwZXmajuT0GBE,1171
70
- tinybird/tb/modules/agent/models.py,sha256=jUEO7i_JwlQVZi6QEUeGyFJMFkPZ4ikyDZdei6s6f3M,628
70
+ tinybird/tb/modules/agent/models.py,sha256=mf8dRCdof6uEFZWh5xQ_D_FStk7eDds7qWRNSbDklUM,589
71
71
  tinybird/tb/modules/agent/prompts.py,sha256=j7nkx1E2BnPP6Ra718FvSDGRWucyFgSX07V9QAiaiGg,4864
72
- tinybird/tb/modules/agent/utils.py,sha256=E785Sq_TLVBi1gaBR53YlHvyP_Kbh4TmRouYl3KHFpo,13080
72
+ tinybird/tb/modules/agent/utils.py,sha256=brW-2StkAy-X1LGDbjQYhOXMSifGwWJCSkPDDmo7SUk,13069
73
73
  tinybird/tb/modules/agent/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
- tinybird/tb/modules/agent/tools/create_datafile.py,sha256=06HK33h86T1d54zvnJXJz_1su3zIS7UJDPyBqhgo81c,1771
75
- tinybird/tb/modules/agent/tools/explore.py,sha256=iEVsi85CRPCPhWcl-fC1J4hYK22TfunxyqNu5pDxdDU,419
76
- tinybird/tb/modules/agent/tools/plan.py,sha256=acMbyjqI6cN7IwmMAC8-MPNSg0PEZVKGEk2NOY4gMi8,1162
74
+ tinybird/tb/modules/agent/tools/create_datafile.py,sha256=V5VMFvpne-LW1XzQY7AnSMiOkMALSRspEjtBqK1Glnk,1858
75
+ tinybird/tb/modules/agent/tools/explore.py,sha256=ihALc_kBcsjrKT3hZyicqyIowB0g_K3AtNNi-5uz9-8,412
76
+ tinybird/tb/modules/agent/tools/plan.py,sha256=K9mXqCgLXbwXtyFFjPvrrwRwEm2rNnIMn73qazDTQts,1345
77
77
  tinybird/tb/modules/agent/tools/preview_datafile.py,sha256=e9q5fR0afApcrntzFrnuHmd10ex7MG_GM6T0Pwc9bRI,850
78
78
  tinybird/tb/modules/datafile/build.py,sha256=NFKBrusFLU0WJNCXePAFWiEDuTaXpwc0lHlOQWEJ43s,51117
79
79
  tinybird/tb/modules/datafile/build_common.py,sha256=2yNdxe49IMA9wNvl25NemY2Iaz8L66snjOdT64dm1is,4511
@@ -95,8 +95,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
95
95
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
96
96
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
97
97
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
98
- tinybird-0.0.1.dev240.dist-info/METADATA,sha256=XT_HpNQ7KOTyQt5ICua7m_CWsFaKQGB0tMvg43YO4XM,1733
99
- tinybird-0.0.1.dev240.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
100
- tinybird-0.0.1.dev240.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
101
- tinybird-0.0.1.dev240.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
102
- tinybird-0.0.1.dev240.dist-info/RECORD,,
98
+ tinybird-0.0.1.dev242.dist-info/METADATA,sha256=jcAeg7hLOB_0X5tNRd6Jchij6S62DjqZ3I4vHblBchk,1733
99
+ tinybird-0.0.1.dev242.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
100
+ tinybird-0.0.1.dev242.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
101
+ tinybird-0.0.1.dev242.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
102
+ tinybird-0.0.1.dev242.dist-info/RECORD,,
@@ -1,42 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Any, Dict, Optional
3
-
4
- import httpx
5
-
6
-
7
- @dataclass
8
- class TinybirdClient:
9
- def __init__(self, host: str, token: str):
10
- self.host = host
11
- self.token = token
12
- self.client = httpx.Client(
13
- timeout=30.0,
14
- headers={"Accept": "application/json", "User-Agent": "Python/APIClient"},
15
- )
16
- self.insights: list[str] = []
17
-
18
- def __aenter__(self):
19
- return self
20
-
21
- def __aexit__(self, exc_type, exc_val, exc_tb):
22
- self.close()
23
-
24
- def close(self):
25
- """Close the underlying HTTP client."""
26
- self.client.close()
27
-
28
- def _get(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> str:
29
- if params is None:
30
- params = {}
31
- params["token"] = self.token
32
- url = f"{self.host}{endpoint}"
33
- response = self.client.get(url, params=params)
34
- try:
35
- response.raise_for_status()
36
- except Exception as e:
37
- raise Exception(response.json().get("error", str(e))) from e
38
- return response.text
39
-
40
- def explore_data(self, prompt: str) -> str:
41
- params = {"prompt": prompt, "host": self.host, "origin": "cli"}
42
- return self._get("/v1/agents/explore", params)