tinybird 0.0.1.dev244__py3-none-any.whl → 0.0.1.dev246__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.

@@ -1698,11 +1698,36 @@ def parse(
1698
1698
  def version(*args: str, **kwargs: Any) -> None:
1699
1699
  pass # whatever, it's deprecated
1700
1700
 
1701
- @not_supported_yet()
1702
1701
  def shared_with(*args: str, **kwargs: Any) -> None:
1702
+ # Count total workspaces collected
1703
+ total_workspaces = 0
1704
+
1703
1705
  for entries in args:
1704
- # In case they specify multiple workspaces
1705
- doc.shared_with += [workspace.strip() for workspace in entries.splitlines()]
1706
+ # In case they specify multiple workspaces, handle both line-separated and comma-separated values
1707
+ lines = entries.splitlines()
1708
+ for line in lines:
1709
+ # Split by comma and strip whitespace from each workspace name
1710
+ workspaces = [workspace.strip().rstrip(",") for workspace in line.split(",") if workspace.strip()]
1711
+ doc.shared_with += workspaces
1712
+ total_workspaces += len(workspaces)
1713
+
1714
+ # Add warning once if any workspaces were found
1715
+ if total_workspaces > 0:
1716
+ warnings.append(
1717
+ DatafileParseWarning(
1718
+ message=(
1719
+ f"{kwargs['cmd'].upper()} is not fully implemented in Forward and will be ignored while this warning is present."
1720
+ )
1721
+ )
1722
+ )
1723
+
1724
+ # Validate that at least one workspace was provided
1725
+ if total_workspaces == 0:
1726
+ raise DatafileSyntaxError(
1727
+ "SHARED_WITH requires at least one workspace name",
1728
+ lineno=kwargs["lineno"],
1729
+ pos=1,
1730
+ )
1706
1731
 
1707
1732
  def __init_engine(v: str):
1708
1733
  if not parser_state.current_node:
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.dev244'
8
- __revision__ = '434c7ff'
7
+ __version__ = '0.0.1.dev246'
8
+ __revision__ = '5c11131'
@@ -1,5 +1,5 @@
1
+ import subprocess
1
2
  import sys
2
- import uuid
3
3
  from datetime import datetime
4
4
  from functools import partial
5
5
  from typing import Any
@@ -35,12 +35,17 @@ from tinybird.tb.modules.agent.prompts import (
35
35
  resources_prompt,
36
36
  sql_instructions,
37
37
  )
38
+ from tinybird.tb.modules.agent.tools.build import build
38
39
  from tinybird.tb.modules.agent.tools.create_datafile import create_datafile
40
+ from tinybird.tb.modules.agent.tools.deploy import deploy
41
+ from tinybird.tb.modules.agent.tools.deploy_check import deploy_check
39
42
  from tinybird.tb.modules.agent.tools.explore import explore_data
40
43
  from tinybird.tb.modules.agent.tools.plan import plan
41
44
  from tinybird.tb.modules.agent.tools.preview_datafile import preview_datafile
42
45
  from tinybird.tb.modules.agent.utils import TinybirdAgentContext
43
46
  from tinybird.tb.modules.build_common import process as build_process
47
+ from tinybird.tb.modules.common import _get_tb_client
48
+ from tinybird.tb.modules.deployment_common import create_deployment
44
49
  from tinybird.tb.modules.exceptions import CLIBuildException
45
50
  from tinybird.tb.modules.feedback_manager import FeedbackManager
46
51
  from tinybird.tb.modules.local_common import get_tinybird_local_client
@@ -86,7 +91,9 @@ You have access to the following tools:
86
91
  2. `preview_datafile` - Preview the content of a datafile (datasource, endpoint, materialized, sink, copy, connection).
87
92
  3. `create_datafile` - Create a file in the project folder. Confirmation will be asked by the tool before creating the file.
88
93
  4. `plan` - Plan the creation or update of resources.
89
-
94
+ 5. `build` - Build the project.
95
+ 6. `deploy` - Deploy the project to Tinybird Cloud.
96
+ 7. `deploy_check` - Check if the project can be deployed to Tinybird Cloud before deploying it.
90
97
 
91
98
  # When creating or updating datafiles:
92
99
  1. Use `plan` tool to plan the creation or update of resources.
@@ -140,6 +147,9 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
140
147
  Tool(preview_datafile, docstring_format="google", require_parameter_descriptions=True, takes_ctx=False),
141
148
  Tool(create_datafile, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
142
149
  Tool(plan, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
150
+ Tool(build, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
151
+ Tool(deploy, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
152
+ Tool(deploy_check, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
143
153
  ],
144
154
  )
145
155
 
@@ -147,22 +157,25 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
147
157
  """Keep only the last 5 messages to manage token usage."""
148
158
  return self.messages[-5:] if len(self.messages) > 5 else self.messages
149
159
 
150
- def run(self, user_prompt: str, project: Project) -> None:
160
+ def run(self, user_prompt: str, config: dict[str, Any], project: Project) -> None:
151
161
  user_prompt = f"{user_prompt}\n\n# Existing resources in the project:\n{resources_prompt(project)}"
152
162
  client = TinyB(token=self.token, host=self.host)
153
163
  folder = self.project.folder
164
+
154
165
  thinking_animation = ThinkingAnimation(message="Chirping", delay=0.15)
155
166
  thinking_animation.start()
156
-
157
167
  result = self.agent.run_sync(
158
168
  user_prompt,
159
169
  deps=TinybirdAgentContext(
160
170
  # context does not support the whole client, so we need to pass only the functions we need
161
171
  explore_data=client.explore_data,
162
- build_project=partial(build_project, folder=folder),
172
+ build_project=partial(build_project, project=project, config=config),
173
+ deploy_project=partial(deploy_project, project=project, config=config),
174
+ deploy_check_project=partial(deploy_check_project, project=project, config=config),
163
175
  get_project_files=project.get_project_files,
164
176
  folder=folder,
165
177
  thinking_animation=thinking_animation,
178
+ workspace_name=self.project.workspace_name,
166
179
  ),
167
180
  message_history=self.messages,
168
181
  )
@@ -182,9 +195,11 @@ def run_agent(config: dict[str, Any], project: Project):
182
195
  host = config["host"]
183
196
  agent = TinybirdAgent(token, host, project)
184
197
  click.echo()
185
- click.echo(FeedbackManager.success(message="Welcome to Tinybird Code"))
186
- click.echo(FeedbackManager.info(message="Describe what you want to create and I'll help you build it"))
187
- click.echo(FeedbackManager.info(message="Commands: 'exit', 'quit', 'help', or Ctrl+C to exit"))
198
+ if config.get("token"):
199
+ click.echo(FeedbackManager.info(message="Describe what you want to create and I'll help you build it"))
200
+ click.echo(FeedbackManager.info(message="Run /help for more commands"))
201
+ else:
202
+ click.echo(FeedbackManager.info(message="Run /login to authenticate"))
188
203
  click.echo()
189
204
 
190
205
  except Exception as e:
@@ -207,25 +222,29 @@ def run_agent(config: dict[str, Any], project: Project):
207
222
  ),
208
223
  )
209
224
 
210
- if user_input.lower() in ["exit", "quit"]:
225
+ if user_input.lower() in ["/exit", "/quit"]:
211
226
  click.echo(FeedbackManager.info(message="Goodbye!"))
212
227
  break
213
- elif user_input.lower() == "clear":
228
+ elif user_input.lower() == "/clear":
214
229
  clear_history()
215
230
  continue
216
- elif user_input.lower() == "help":
231
+ elif user_input.lower() == "/login":
232
+ click.echo()
233
+ subprocess.run(["tb", "login"], check=True)
234
+ click.echo()
235
+ continue
236
+ elif user_input.lower() == "/help":
217
237
  click.echo()
218
- click.echo(FeedbackManager.info(message="Tinybird Code Help:"))
219
238
  click.echo("• Describe what you want to create: 'Create a user analytics system'")
220
239
  click.echo("• Ask for specific resources: 'Create a pipe to aggregate daily clicks'")
221
- click.echo("• Request data sources: 'Set up a Kafka connection for events'")
222
- click.echo("• Type 'exit' or 'quit' to leave")
240
+ click.echo("• Connect to external services: 'Set up a Kafka connection for events'")
241
+ click.echo("• Type '/exit' or '/quit' to leave")
223
242
  click.echo()
224
243
  continue
225
244
  elif user_input.strip() == "":
226
245
  continue
227
246
  else:
228
- agent.run(user_input, project)
247
+ agent.run(user_input, config, project)
229
248
 
230
249
  except KeyboardInterrupt:
231
250
  click.echo(FeedbackManager.info(message="Goodbye!"))
@@ -239,10 +258,34 @@ def run_agent(config: dict[str, Any], project: Project):
239
258
  sys.exit(1)
240
259
 
241
260
 
242
- def build_project(folder: str) -> None:
243
- workspace_name = f"tmp_workspace_{uuid.uuid4()}"
244
- project = Project(folder, workspace_name=workspace_name)
245
- local_client = get_tinybird_local_client({"path": folder, "name": workspace_name}, test=True, silent=True)
246
- build_error = build_process(project=project, tb_client=local_client, watch=False, silent=True, exit_on_error=False)
261
+ def build_project(config: dict[str, Any], project: Project, silent: bool = True, test: bool = True) -> None:
262
+ local_client = get_tinybird_local_client(config, test=test, silent=silent)
263
+ build_error = build_process(
264
+ project=project, tb_client=local_client, watch=False, silent=silent, exit_on_error=False
265
+ )
247
266
  if build_error:
248
267
  raise CLIBuildException(build_error)
268
+
269
+
270
+ def deploy_project(config: dict[str, Any], project: Project) -> None:
271
+ client = _get_tb_client(config["token"], config["host"])
272
+ create_deployment(
273
+ project=project,
274
+ client=client,
275
+ config=config,
276
+ wait=True,
277
+ auto=True,
278
+ allow_destructive_operations=False,
279
+ )
280
+
281
+
282
+ def deploy_check_project(config: dict[str, Any], project: Project) -> None:
283
+ client = _get_tb_client(config["token"], config["host"])
284
+ create_deployment(
285
+ project=project,
286
+ client=client,
287
+ config=config,
288
+ check=True,
289
+ wait=True,
290
+ auto=True,
291
+ )
@@ -5,23 +5,23 @@ from tinybird.tb.modules.project import Project
5
5
  plan_instructions = """
6
6
  When asked to create a plan, you MUST respond with this EXACT format and NOTHING ELSE:
7
7
 
8
- PLAN_DESCRIPTION: [One sentence describing what will be built]
9
-
10
- STEPS:
11
- 1. CREATE_DATASOURCE: [name] - [description] - DEPENDS_ON: none
12
- 2. CREATE_ENDPOINT: [name] - [description] - DEPENDS_ON: [resource_name]
13
- 3. CREATE_MATERIALIZED_PIPE: [name] - [description] - DEPENDS_ON: [resource_name]
14
- 4. CREATE_MATERIALIZED_DATASOURCE: [name] - [description] - DEPENDS_ON: [resource_name]
15
- 5. CREATE_SINK: [name] - [description] - DEPENDS_ON: [resource_name]
16
- 6. CREATE_COPY: [name] - [description] - DEPENDS_ON: [resource_name]
17
- 7. CREATE_CONNECTION: [name] - [description] - DEPENDS_ON: none
8
+ Plan description: [One sentence describing what will be built]
9
+
10
+ Steps:
11
+ 1. Connection: [name] - [description] - Depends on: none
12
+ 2. Datasource: [name] - [description] - Depends on: [connection_name (optional)]
13
+ 3. Endpoint: [name] - [description] - Depends on: [resources]
14
+ 4. Materialized pipe: [name] - [description] - Depends on: [resources]
15
+ 5. Materialized datasource: [name] - [description] - Depends on: [resources]
16
+ 6. Sink: [name] - [description] - Depends on: [resources]
17
+ 7. Copy: [name] - [description] - Depends on: [resources]
18
+ 8. Build project
18
19
 
19
20
  You can skip steps where resources will not be created or updated.
21
+ Always add BUILD_PROJECT step at the end of the plan.
20
22
 
21
- ESTIMATED_RESOURCES: [total number of steps]
22
-
23
- RESOURCE_DEPENDENCIES:
24
- [resource_name]: [resource_name]
23
+ Resource dependencies:
24
+ [resource_name]: [resources]
25
25
  """
26
26
 
27
27
 
@@ -0,0 +1,19 @@
1
+ import click
2
+ from pydantic_ai import RunContext
3
+
4
+ from tinybird.tb.modules.agent.utils import TinybirdAgentContext
5
+ from tinybird.tb.modules.feedback_manager import FeedbackManager
6
+
7
+
8
+ def build(ctx: RunContext[TinybirdAgentContext]) -> str:
9
+ """Build the project"""
10
+ try:
11
+ ctx.deps.thinking_animation.stop()
12
+ ctx.deps.build_project(test=False, silent=False)
13
+ ctx.deps.thinking_animation.start()
14
+ return "Project built successfully"
15
+ except Exception as e:
16
+ ctx.deps.thinking_animation.stop()
17
+ click.echo(FeedbackManager.error(message=e))
18
+ ctx.deps.thinking_animation.start()
19
+ return f"Error building project: {e}"
@@ -44,17 +44,17 @@ def create_datafile(ctx: RunContext[TinybirdAgentContext], resource: Datafile) -
44
44
  path = Path(ctx.deps.folder) / resource.pathname
45
45
  exists = str(path) in ctx.deps.get_project_files()
46
46
  confirmation = get_resource_confirmation(resource, exists)
47
- ctx.deps.thinking_animation.start()
48
47
 
49
48
  if not confirmation:
49
+ ctx.deps.thinking_animation.start()
50
50
  return f"Resource {resource.pathname} was not created. User cancelled creation."
51
51
 
52
52
  folder_path = path.parent
53
53
  folder_path.mkdir(parents=True, exist_ok=True)
54
54
  path.touch(exist_ok=True)
55
-
56
55
  path.write_text(resource.content)
57
- ctx.deps.build_project()
56
+ ctx.deps.build_project(test=True, silent=True)
57
+ ctx.deps.thinking_animation.start()
58
58
  return f"Created {resource.pathname}"
59
59
 
60
60
  except CLIBuildException as e:
@@ -0,0 +1,45 @@
1
+ import click
2
+ from pydantic_ai import RunContext
3
+
4
+ from tinybird.tb.modules.agent.utils import TinybirdAgentContext, show_options
5
+ from tinybird.tb.modules.feedback_manager import FeedbackManager
6
+
7
+
8
+ def get_deploy_confirmation() -> bool:
9
+ """Get user confirmation for deploying the project"""
10
+ while True:
11
+ result = show_options(
12
+ options=["Yes, deploy the project", "No, and tell Tinybird Code what to do"],
13
+ title="Do you want to deploy the project?",
14
+ )
15
+
16
+ if result is None: # Cancelled
17
+ return False
18
+
19
+ if result.startswith("Yes"):
20
+ return True
21
+ elif result.startswith("No"):
22
+ return False
23
+
24
+ return False
25
+
26
+
27
+ def deploy(ctx: RunContext[TinybirdAgentContext]) -> str:
28
+ """Deploy the project"""
29
+ try:
30
+ ctx.deps.thinking_animation.stop()
31
+ confirmation = get_deploy_confirmation()
32
+ ctx.deps.thinking_animation.start()
33
+
34
+ if not confirmation:
35
+ return "User cancelled deployment."
36
+
37
+ ctx.deps.thinking_animation.stop()
38
+ ctx.deps.deploy_project()
39
+ ctx.deps.thinking_animation.start()
40
+ return "Project deployed successfully"
41
+ except Exception as e:
42
+ ctx.deps.thinking_animation.stop()
43
+ click.echo(FeedbackManager.error(message=e))
44
+ ctx.deps.thinking_animation.start()
45
+ return f"Error depoying project: {e}"
@@ -0,0 +1,19 @@
1
+ import click
2
+ from pydantic_ai import RunContext
3
+
4
+ from tinybird.tb.modules.agent.utils import TinybirdAgentContext
5
+ from tinybird.tb.modules.feedback_manager import FeedbackManager
6
+
7
+
8
+ def deploy_check(ctx: RunContext[TinybirdAgentContext]) -> str:
9
+ """Check that project can be deployed"""
10
+ try:
11
+ ctx.deps.thinking_animation.stop()
12
+ ctx.deps.deploy_check_project()
13
+ ctx.deps.thinking_animation.start()
14
+ return "Project can be deployed"
15
+ except Exception as e:
16
+ ctx.deps.thinking_animation.stop()
17
+ click.echo(FeedbackManager.error(message=e))
18
+ ctx.deps.thinking_animation.start()
19
+ return f"Project cannot be deployed: {e}"
@@ -18,11 +18,14 @@ from pydantic import BaseModel, Field
18
18
 
19
19
 
20
20
  class TinybirdAgentContext(BaseModel):
21
- explore_data: Callable[[str], str]
22
21
  folder: str
23
- build_project: Callable[[], None]
22
+ workspace_name: str
24
23
  thinking_animation: Any
25
24
  get_project_files: Callable[[], List[str]]
25
+ explore_data: Callable[[str], str]
26
+ build_project: Callable[..., None]
27
+ deploy_project: Callable[[], None]
28
+ deploy_check_project: Callable[[], None]
26
29
 
27
30
 
28
31
  default_style = Style.from_dict(