tinybird 0.0.1.dev250__py3-none-any.whl → 0.0.1.dev252__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.dev250'
8
- __revision__ = '1c47b89'
7
+ __version__ = '0.0.1.dev252'
8
+ __revision__ = 'd70cad6'
@@ -41,6 +41,7 @@ from tinybird.tb.modules.agent.tools.deploy import deploy
41
41
  from tinybird.tb.modules.agent.tools.deploy_check import deploy_check
42
42
  from tinybird.tb.modules.agent.tools.explore import explore_data
43
43
  from tinybird.tb.modules.agent.tools.get_endpoint_stats import get_endpoint_stats
44
+ from tinybird.tb.modules.agent.tools.get_openapi_definition import get_openapi_definition
44
45
  from tinybird.tb.modules.agent.tools.mock import mock
45
46
  from tinybird.tb.modules.agent.tools.plan import plan
46
47
  from tinybird.tb.modules.agent.tools.preview_datafile import preview_datafile
@@ -114,6 +115,7 @@ You have access to the following tools:
114
115
  9. `read_fixture_data` - Read a fixture data file present in the project folder.
115
116
  10. `append` - Append existing fixture to a datasource.
116
117
  11. `get_endpoint_stats` - Get metrics of the requests to an endpoint.
118
+ 12. `get_openapi_definition` - Get the OpenAPI definition for all endpoints that are built/deployed to Tinybird Cloud or Local.
117
119
 
118
120
  # When creating or updating datafiles:
119
121
  1. Use `plan` tool to plan the creation or update of resources.
@@ -195,6 +197,12 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
195
197
  Tool(
196
198
  get_endpoint_stats, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True
197
199
  ),
200
+ Tool(
201
+ get_openapi_definition,
202
+ docstring_format="google",
203
+ require_parameter_descriptions=True,
204
+ takes_ctx=True,
205
+ ),
198
206
  ],
199
207
  )
200
208
 
@@ -227,6 +235,9 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
227
235
  thinking_animation=thinking_animation,
228
236
  workspace_name=self.project.workspace_name,
229
237
  dangerously_skip_permissions=self.dangerously_skip_permissions,
238
+ token=self.token,
239
+ user_token=self.user_token,
240
+ host=self.host,
230
241
  ),
231
242
  message_history=self.messages,
232
243
  )
@@ -243,11 +254,13 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
243
254
  )
244
255
  click.echo(result.output)
245
256
  click.echo("\n")
246
- click.echo(f"Input tokens: {request_tokens}")
247
- click.echo(f"Output tokens: {response_tokens}")
248
- click.echo(f"Total tokens: {total_tokens}")
249
- click.echo(f"Cost: ${cost:.6f}")
250
- click.echo("\n")
257
+
258
+ if "@tinybird.co" in config.get("user_email", ""):
259
+ click.echo(f"Input tokens: {request_tokens}")
260
+ click.echo(f"Output tokens: {response_tokens}")
261
+ click.echo(f"Total tokens: {total_tokens}")
262
+ click.echo(f"Cost: ${cost:.6f}")
263
+ click.echo("\n")
251
264
 
252
265
 
253
266
  def run_agent(config: dict[str, Any], project: Project, dangerously_skip_permissions: bool):
@@ -378,7 +391,12 @@ def append_data(config: dict[str, Any], datasource_name: str, path: str) -> None
378
391
 
379
392
 
380
393
  def mock_data(
381
- config: dict[str, Any], project: Project, datasource_name: str, data_format: str, rows: int
394
+ config: dict[str, Any],
395
+ project: Project,
396
+ datasource_name: str,
397
+ data_format: str,
398
+ rows: int,
399
+ context: Optional[str] = None,
382
400
  ) -> list[dict[str, Any]]:
383
401
  client = get_tinybird_local_client(config, test=False, silent=False)
384
402
  cli_config = CLIConfig.get_project_config()
@@ -388,12 +406,11 @@ def mock_data(
388
406
  raise CLIMockException(f"Datasource {datasource_name} not found")
389
407
 
390
408
  datasource_content = Path(datasource_path).read_text()
391
- prompt = ""
392
409
  return create_mock_data(
393
410
  datasource_name,
394
411
  datasource_content,
395
412
  rows,
396
- prompt,
413
+ context or "",
397
414
  cli_config,
398
415
  config,
399
416
  cli_config.get_user_token() or "",
@@ -22,16 +22,17 @@ def append(ctx: RunContext[TinybirdAgentContext], datasource_name: str, fixture_
22
22
  skip_confirmation=ctx.deps.dangerously_skip_permissions,
23
23
  )
24
24
 
25
- ctx.deps.thinking_animation.start()
26
-
27
25
  if confirmation == "review":
28
26
  click.echo()
29
27
  feedback = show_input(ctx.deps.workspace_name)
30
28
  ctx.deps.thinking_animation.start()
31
- return f"User did not confirm the proposed plan and gave the following feedback: {feedback}"
29
+ return (
30
+ f"User did not confirm appending {fixture_pathname} fixture and gave the following feedback: {feedback}"
31
+ )
32
32
 
33
33
  if confirmation == "cancel":
34
- return "User rejected appending existing fixture. Skipping..."
34
+ ctx.deps.thinking_animation.start()
35
+ return f"User rejected appending {fixture_pathname} fixture. Skip this step"
35
36
 
36
37
  ctx.deps.thinking_animation.stop()
37
38
  click.echo(FeedbackManager.highlight(message=f"\n» Appending {fixture_pathname} to {datasource_name}..."))
@@ -0,0 +1,39 @@
1
+ import click
2
+ import requests
3
+ from pydantic_ai import RunContext
4
+
5
+ from tinybird.tb.modules.agent.utils import TinybirdAgentContext
6
+ from tinybird.tb.modules.feedback_manager import FeedbackManager
7
+
8
+
9
+ def get_openapi_definition(ctx: RunContext[TinybirdAgentContext], cloud: bool = True):
10
+ """Get the OpenAPI definition for all endpoints in the project:
11
+
12
+ Args:
13
+ cloud (bool): Whether to get the OpenAPI spec from cloud or local. Optional.
14
+
15
+ Returns:
16
+ str: The OpenAPI spec for all endpoints in the project.
17
+ """
18
+
19
+ cloud_or_local = "Cloud" if cloud else "Local"
20
+ ctx.deps.thinking_animation.stop()
21
+
22
+ click.echo(FeedbackManager.highlight(message=f"» Accessing Tinybird {cloud_or_local} endpoints"))
23
+ try:
24
+ url = f"{ctx.deps.host}/v0/pipes/openapi.json"
25
+
26
+ result = requests.get(url, headers={"Authorization": f"Bearer {ctx.deps.token}"})
27
+ if result.status_code != 200:
28
+ raise Exception(f"Failed to get OpenAPI spec: {result.status_code} {result.text}")
29
+
30
+ openapi_spec = result.text
31
+
32
+ click.echo(FeedbackManager.success(message="✓ Done!"))
33
+ click.echo()
34
+ ctx.deps.thinking_animation.start()
35
+ return f"OpenAPI spec for {cloud_or_local} endpoints: {openapi_spec}. <dev_note>Add the base url to each path so the user can copy paste if needed: {ctx.deps.host}</dev_note>"
36
+ except Exception as e:
37
+ click.echo(FeedbackManager.error(message=f"Error getting OpenAPI spec: {e}"))
38
+ ctx.deps.thinking_animation.start()
39
+ return f"Error getting OpenAPI spec: {e}"
@@ -1,3 +1,5 @@
1
+ from typing import Optional
2
+
1
3
  import click
2
4
  from pydantic_ai import RunContext
3
5
 
@@ -6,13 +8,20 @@ from tinybird.tb.modules.datafile.fixture import persist_fixture
6
8
  from tinybird.tb.modules.feedback_manager import FeedbackManager
7
9
 
8
10
 
9
- def mock(ctx: RunContext[TinybirdAgentContext], datasource_name: str, data_format: str, rows: int) -> str:
11
+ def mock(
12
+ ctx: RunContext[TinybirdAgentContext],
13
+ datasource_name: str,
14
+ data_format: str,
15
+ rows: int,
16
+ context: Optional[str] = None,
17
+ ) -> str:
10
18
  """Create mock data for a datasource
11
19
 
12
20
  Args:
13
21
  datasource_name: Name of the datasource to create mock data for
14
22
  data_format: Format of the mock data to create. Options: ndjson, csv
15
23
  rows: Number of rows to create. If not provided, the default is 10
24
+ context: Extra context to be used to generate the mock data. Optional.
16
25
 
17
26
  Returns:
18
27
  str: Message indicating the success or failure of the mock data generation
@@ -35,7 +44,7 @@ def mock(ctx: RunContext[TinybirdAgentContext], datasource_name: str, data_forma
35
44
  return "User cancelled mock data generation. Stop mock data generation."
36
45
 
37
46
  click.echo(FeedbackManager.highlight(message=f"\n» Generating mock data for {datasource_name}..."))
38
- data = ctx.deps.mock_data(datasource_name=datasource_name, data_format=data_format, rows=rows)
47
+ data = ctx.deps.mock_data(datasource_name=datasource_name, data_format=data_format, rows=rows, context=context)
39
48
  fixture_path = persist_fixture(datasource_name, data, ctx.deps.folder, format=data_format)
40
49
  ctx.deps.append_data(datasource_name=datasource_name, path=str(fixture_path))
41
50
  click.echo(FeedbackManager.success(message=f"✓ Data generated for {datasource_name}"))
@@ -43,6 +52,22 @@ def mock(ctx: RunContext[TinybirdAgentContext], datasource_name: str, data_forma
43
52
  return f"Mock data generated successfully for datasource {datasource_name}"
44
53
  except Exception as e:
45
54
  ctx.deps.thinking_animation.stop()
46
- click.echo(FeedbackManager.error(message=e))
55
+ error_message = str(e)
56
+ click.echo(FeedbackManager.error(message=error_message))
57
+ try:
58
+ if "in quarantine" in error_message:
59
+ click.echo(
60
+ FeedbackManager.highlight(message=f"\n» Looking for errors in {datasource_name}_quarantine...")
61
+ )
62
+ query = f"select * from {datasource_name}_quarantine order by insertion_date desc limit 5 FORMAT CSVWithNames"
63
+ quarantine_data = ctx.deps.execute_local_query(query=query)
64
+ error_message = (
65
+ error_message
66
+ + f"\nThese are the first 5 rows of the quarantine table for datasource '{datasource_name}':\n{quarantine_data}. Use again `mock` tool but add this issue to the context."
67
+ )
68
+
69
+ except Exception as quarantine_error:
70
+ error_message = error_message + f"\nError accessing to {datasource_name}_quarantine: {quarantine_error}"
71
+
47
72
  ctx.deps.thinking_animation.start()
48
- return f"Error generating mock data: {e}"
73
+ return f"Error generating mock data: {error_message}"
@@ -13,7 +13,6 @@ from prompt_toolkit.layout import Layout
13
13
  from prompt_toolkit.layout.containers import ConditionalContainer, HSplit, Window
14
14
  from prompt_toolkit.layout.controls import FormattedTextControl
15
15
  from prompt_toolkit.layout.dimension import LayoutDimension as D
16
- from prompt_toolkit.mouse_events import MouseEventType
17
16
  from prompt_toolkit.patch_stdout import patch_stdout as pt_patch_stdout
18
17
  from prompt_toolkit.shortcuts import PromptSession
19
18
  from prompt_toolkit.styles import Style as PromptStyle
@@ -45,6 +44,9 @@ class TinybirdAgentContext(BaseModel):
45
44
  execute_cloud_query: Callable[..., str]
46
45
  execute_local_query: Callable[..., str]
47
46
  dangerously_skip_permissions: bool
47
+ token: str
48
+ user_token: str
49
+ host: str
48
50
 
49
51
 
50
52
  default_style = PromptStyle.from_dict(
@@ -60,16 +62,6 @@ default_style = PromptStyle.from_dict(
60
62
  )
61
63
 
62
64
 
63
- def if_mousedown(handler):
64
- def handle_if_mouse_down(mouse_event):
65
- if mouse_event.event_type == MouseEventType.MOUSE_DOWN:
66
- return handler(mouse_event)
67
- else:
68
- return NotImplemented
69
-
70
- return handle_if_mouse_down
71
-
72
-
73
65
  class Separator:
74
66
  line = "-" * 15
75
67
 
@@ -130,9 +122,7 @@ class InquirerControl(FormattedTextControl):
130
122
  def append(index, choice):
131
123
  selected = index == self.selected_option_index
132
124
 
133
- @if_mousedown
134
- def select_item(mouse_event):
135
- # bind option with this index to mouse event
125
+ def select_item():
136
126
  self.selected_option_index = index
137
127
  self.answered = True
138
128
  get_app().exit(result=self.get_selection()[0])
@@ -245,7 +235,7 @@ def prompt_question(message, **kwargs):
245
235
  ic.answered = True
246
236
  event.app.exit(result=ic.get_selection()[1])
247
237
 
248
- return Application(layout=Layout(layout), key_bindings=kb, mouse_support=True, style=style)
238
+ return Application(layout=Layout(layout), key_bindings=kb, mouse_support=False, style=style)
249
239
 
250
240
 
251
241
  def prompt(questions, answers=None, **kwargs):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev250
3
+ Version: 0.0.1.dev252
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=VsfwyuLYgBIFXG2ts697b2_s6ncyZZMxVTvvxBR-C68,247
20
+ tinybird/tb/__cli__.py,sha256=tux3rAKuHbXOtIaG9CZQxDsezngoOjC_cZmI7OXF1UY,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,22 +68,23 @@ 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=OLJFtfgwWa3rNjf8Uwu2dtKVhxnTfZD__lXlAGQTUL4,20532
71
+ tinybird/tb/modules/agent/agent.py,sha256=Uxo2FNNu-YW-J-AbZizZe0eKYKdZRwbPJCgA9EsXlgs,21208
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
74
  tinybird/tb/modules/agent/memory.py,sha256=H6SJK--2L5C87B7AJd_jMqsq3sCvFvZwZXmajuT0GBE,1171
75
75
  tinybird/tb/modules/agent/models.py,sha256=LW1D27gjcd_jwFmghEzteCgToDfodX2B6B5S8BYbysw,735
76
76
  tinybird/tb/modules/agent/prompts.py,sha256=wbe6vUnm-fskceWgP13R5VW1v_YF7_wLDe-wBN6rlWw,6998
77
- tinybird/tb/modules/agent/utils.py,sha256=bqE6Edr6giOVjuxusHsNYiMp4F0HV1aek2ZE9r1URPg,26471
77
+ tinybird/tb/modules/agent/utils.py,sha256=fOliFWZ1A6_SBjwreJDid53cMFjH1Ah4pe5DumPSolE,26111
78
78
  tinybird/tb/modules/agent/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
79
- tinybird/tb/modules/agent/tools/append.py,sha256=Db576-ziulykJyaWl03zUp-KI-NVURh0WcFIAPNbNPw,1974
79
+ tinybird/tb/modules/agent/tools/append.py,sha256=cBdKBhUW0kooIbywtZNd_bhxbbMyf5NUKHwanAl5BmA,2042
80
80
  tinybird/tb/modules/agent/tools/build.py,sha256=LhzJMx6tbxC7gogIrxhfKJc-SDgoSR-FC6IunfaCdn8,758
81
81
  tinybird/tb/modules/agent/tools/create_datafile.py,sha256=wcPcChACTIFKw0lKFTlhm0sWJKhQkMLPLnGNpKyeETA,2962
82
82
  tinybird/tb/modules/agent/tools/deploy.py,sha256=WrsSlaufKGOBx0S13uoMQQH2DnKue5LQ231Rx4RXh2I,1443
83
83
  tinybird/tb/modules/agent/tools/deploy_check.py,sha256=VqMYC7l3_cihmmM_pi8w1t8rJ3P0xDc7pHs_st9k-9Q,684
84
84
  tinybird/tb/modules/agent/tools/explore.py,sha256=ihALc_kBcsjrKT3hZyicqyIowB0g_K3AtNNi-5uz9-8,412
85
85
  tinybird/tb/modules/agent/tools/get_endpoint_stats.py,sha256=_3wAvDykJitIOb5BRnP7wCy6y06y1qlULHLWB-MvS2M,1705
86
- tinybird/tb/modules/agent/tools/mock.py,sha256=1DeHv14M1dzzKV78kKte9xWQg7RUdQIdXH8KilnQPP0,2304
86
+ tinybird/tb/modules/agent/tools/get_openapi_definition.py,sha256=9cQ-SUeB1NVhPJN1s8aQh9KQxqI9-DEEW1Ot5r2JbOk,1575
87
+ tinybird/tb/modules/agent/tools/mock.py,sha256=Omog_gdEdm8YuBXNrJdHwxHqjL_ji9UIr75mALF4ozI,3408
87
88
  tinybird/tb/modules/agent/tools/plan.py,sha256=pr6LnItz6vlOeCG8GE459ExsrBEG0KLx-g02SZGNjXU,1217
88
89
  tinybird/tb/modules/agent/tools/preview_datafile.py,sha256=e9q5fR0afApcrntzFrnuHmd10ex7MG_GM6T0Pwc9bRI,850
89
90
  tinybird/tb/modules/agent/tools/read_fixture_data.py,sha256=rvTdVlZsu3rQTSWqXzpFt4LEwnBcMLIT8hlI5C7MVN4,1430
@@ -107,8 +108,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
107
108
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
108
109
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
109
110
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
110
- tinybird-0.0.1.dev250.dist-info/METADATA,sha256=5urJcqt4JiSsBmETS17ZeDZ20R3QVzATLCXLNuuIiSQ,1733
111
- tinybird-0.0.1.dev250.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
112
- tinybird-0.0.1.dev250.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
113
- tinybird-0.0.1.dev250.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
114
- tinybird-0.0.1.dev250.dist-info/RECORD,,
111
+ tinybird-0.0.1.dev252.dist-info/METADATA,sha256=5RXjrDqF3SKasGIPyA3n9a5ZbKyFwrNxwxP-SwnVprk,1733
112
+ tinybird-0.0.1.dev252.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
113
+ tinybird-0.0.1.dev252.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
114
+ tinybird-0.0.1.dev252.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
115
+ tinybird-0.0.1.dev252.dist-info/RECORD,,