tinybird 0.0.1.dev246__tar.gz → 0.0.1.dev247__tar.gz
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-0.0.1.dev246 → tinybird-0.0.1.dev247}/PKG-INFO +1 -1
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/ch_utils/constants.py +2 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/__cli__.py +2 -2
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/agent.py +74 -8
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/models.py +6 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/prompts.py +57 -29
- tinybird-0.0.1.dev247/tinybird/tb/modules/agent/tools/append.py +55 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/tools/build.py +1 -0
- tinybird-0.0.1.dev247/tinybird/tb/modules/agent/tools/create_datafile.py +145 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/tools/deploy.py +1 -1
- tinybird-0.0.1.dev247/tinybird/tb/modules/agent/tools/mock.py +59 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/tools/plan.py +1 -1
- tinybird-0.0.1.dev247/tinybird/tb/modules/agent/tools/read_fixture_data.py +28 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/utils.py +4 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/build.py +4 -1
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/build_common.py +2 -3
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/cli.py +9 -1
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/create.py +1 -1
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/feedback_manager.py +1 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/llm.py +1 -1
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/mock.py +3 -69
- tinybird-0.0.1.dev247/tinybird/tb/modules/mock_common.py +71 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/project.py +9 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird.egg-info/PKG-INFO +1 -1
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird.egg-info/SOURCES.txt +4 -0
- tinybird-0.0.1.dev246/tinybird/tb/modules/agent/tools/create_datafile.py +0 -66
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/setup.cfg +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/__cli__.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/ch_utils/engine.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/check_pypi.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/client.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/config.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/connectors.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/context.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/datafile/common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/datafile/exceptions.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/datafile/parse_connection.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/datafile/parse_datasource.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/datafile/parse_pipe.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/datatypes.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/feedback_manager.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/git_settings.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/prompts.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/sql.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/sql_template.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/sql_template_fmt.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/sql_toolset.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/syncasync.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/check_pypi.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/cli.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/client.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/config.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/__init__.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/animations.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/banner.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/memory.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/tools/__init__.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/tools/deploy_check.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/tools/explore.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/agent/tools/preview_datafile.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/cicd.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/config.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/connection.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/copy.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/build.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/build_common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/build_datasource.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/build_pipe.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/diff.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/fixture.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/format_common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/format_datasource.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/format_pipe.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/pipe_checker.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/playground.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datafile/pull.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/datasource.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/deployment.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/deployment_common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/deprecations.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/dev_server.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/endpoint.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/exceptions.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/info.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/infra.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/job.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/llm_utils.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/local.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/local_common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/login.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/logout.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/materialization.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/open.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/pipe.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/regions.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/secret.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/secret_common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/shell.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/sink.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/table.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/telemetry.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/test.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/tinyunit/tinyunit.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/tinyunit/tinyunit_lib.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/token.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/watch.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/workspace.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb/modules/workspace_members.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/auth.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/branch.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/cicd.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/cli.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/common.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/config.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/connection.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/datasource.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/exceptions.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/fmt.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/job.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/pipe.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/regions.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/tag.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/telemetry.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/test.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/tinyunit/tinyunit.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/workspace.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tb_cli_modules/workspace_members.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird/tornado_template.py +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird.egg-info/dependency_links.txt +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird.egg-info/entry_points.txt +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird.egg-info/requires.txt +0 -0
- {tinybird-0.0.1.dev246 → tinybird-0.0.1.dev247}/tinybird.egg-info/top_level.txt +0 -0
|
@@ -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.dev247'
|
|
8
|
+
__revision__ = '379a827'
|
|
@@ -2,6 +2,7 @@ import subprocess
|
|
|
2
2
|
import sys
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from functools import partial
|
|
5
|
+
from pathlib import Path
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
7
8
|
import click
|
|
@@ -28,34 +29,40 @@ from tinybird.tb.client import TinyB
|
|
|
28
29
|
from tinybird.tb.modules.agent.animations import ThinkingAnimation
|
|
29
30
|
from tinybird.tb.modules.agent.banner import display_banner
|
|
30
31
|
from tinybird.tb.modules.agent.memory import clear_history, load_history
|
|
31
|
-
from tinybird.tb.modules.agent.models import create_model
|
|
32
|
+
from tinybird.tb.modules.agent.models import create_model, model_costs
|
|
32
33
|
from tinybird.tb.modules.agent.prompts import (
|
|
33
34
|
datafile_instructions,
|
|
34
35
|
plan_instructions,
|
|
35
36
|
resources_prompt,
|
|
36
37
|
sql_instructions,
|
|
37
38
|
)
|
|
39
|
+
from tinybird.tb.modules.agent.tools.append import append
|
|
38
40
|
from tinybird.tb.modules.agent.tools.build import build
|
|
39
41
|
from tinybird.tb.modules.agent.tools.create_datafile import create_datafile
|
|
40
42
|
from tinybird.tb.modules.agent.tools.deploy import deploy
|
|
41
43
|
from tinybird.tb.modules.agent.tools.deploy_check import deploy_check
|
|
42
44
|
from tinybird.tb.modules.agent.tools.explore import explore_data
|
|
45
|
+
from tinybird.tb.modules.agent.tools.mock import mock
|
|
43
46
|
from tinybird.tb.modules.agent.tools.plan import plan
|
|
44
47
|
from tinybird.tb.modules.agent.tools.preview_datafile import preview_datafile
|
|
48
|
+
from tinybird.tb.modules.agent.tools.read_fixture_data import read_fixture_data
|
|
45
49
|
from tinybird.tb.modules.agent.utils import TinybirdAgentContext
|
|
46
50
|
from tinybird.tb.modules.build_common import process as build_process
|
|
47
|
-
from tinybird.tb.modules.common import _get_tb_client
|
|
51
|
+
from tinybird.tb.modules.common import _analyze, _get_tb_client
|
|
52
|
+
from tinybird.tb.modules.config import CLIConfig
|
|
48
53
|
from tinybird.tb.modules.deployment_common import create_deployment
|
|
49
|
-
from tinybird.tb.modules.exceptions import CLIBuildException
|
|
54
|
+
from tinybird.tb.modules.exceptions import CLIBuildException, CLIMockException
|
|
50
55
|
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
51
56
|
from tinybird.tb.modules.local_common import get_tinybird_local_client
|
|
57
|
+
from tinybird.tb.modules.mock_common import append_mock_data, create_mock_data
|
|
52
58
|
from tinybird.tb.modules.project import Project
|
|
53
59
|
|
|
54
60
|
|
|
55
61
|
class TinybirdAgent:
|
|
56
|
-
def __init__(self, token: str, host: str, project: Project):
|
|
62
|
+
def __init__(self, token: str, host: str, project: Project, dangerously_skip_permissions: bool):
|
|
57
63
|
self.token = token
|
|
58
64
|
self.host = host
|
|
65
|
+
self.dangerously_skip_permissions = dangerously_skip_permissions
|
|
59
66
|
self.project = project
|
|
60
67
|
self.messages: list[ModelMessage] = []
|
|
61
68
|
self.agent = Agent(
|
|
@@ -94,6 +101,9 @@ You have access to the following tools:
|
|
|
94
101
|
5. `build` - Build the project.
|
|
95
102
|
6. `deploy` - Deploy the project to Tinybird Cloud.
|
|
96
103
|
7. `deploy_check` - Check if the project can be deployed to Tinybird Cloud before deploying it.
|
|
104
|
+
8. `mock` - Create mock data for a landing datasource.
|
|
105
|
+
9. `read_fixture_data` - Read a fixture data file present in the project folder.
|
|
106
|
+
10. `append` - Append existing fixture to a datasource.
|
|
97
107
|
|
|
98
108
|
# When creating or updating datafiles:
|
|
99
109
|
1. Use `plan` tool to plan the creation or update of resources.
|
|
@@ -150,6 +160,9 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
|
|
|
150
160
|
Tool(build, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
|
|
151
161
|
Tool(deploy, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
|
|
152
162
|
Tool(deploy_check, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
|
|
163
|
+
Tool(mock, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
|
|
164
|
+
Tool(read_fixture_data, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
|
|
165
|
+
Tool(append, docstring_format="google", require_parameter_descriptions=True, takes_ctx=True),
|
|
153
166
|
],
|
|
154
167
|
)
|
|
155
168
|
|
|
@@ -158,7 +171,7 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
|
|
|
158
171
|
return self.messages[-5:] if len(self.messages) > 5 else self.messages
|
|
159
172
|
|
|
160
173
|
def run(self, user_prompt: str, config: dict[str, Any], project: Project) -> None:
|
|
161
|
-
user_prompt = f"{user_prompt}\n\n
|
|
174
|
+
user_prompt = f"{user_prompt}\n\n{resources_prompt(project)}"
|
|
162
175
|
client = TinyB(token=self.token, host=self.host)
|
|
163
176
|
folder = self.project.folder
|
|
164
177
|
|
|
@@ -172,28 +185,44 @@ Today is {datetime.now().strftime("%Y-%m-%d")}
|
|
|
172
185
|
build_project=partial(build_project, project=project, config=config),
|
|
173
186
|
deploy_project=partial(deploy_project, project=project, config=config),
|
|
174
187
|
deploy_check_project=partial(deploy_check_project, project=project, config=config),
|
|
188
|
+
mock_data=partial(mock_data, project=project, config=config),
|
|
189
|
+
append_data=partial(append_data, config=config),
|
|
190
|
+
analyze_fixture=partial(analyze_fixture, config=config),
|
|
175
191
|
get_project_files=project.get_project_files,
|
|
176
192
|
folder=folder,
|
|
177
193
|
thinking_animation=thinking_animation,
|
|
178
194
|
workspace_name=self.project.workspace_name,
|
|
195
|
+
dangerously_skip_permissions=self.dangerously_skip_permissions,
|
|
179
196
|
),
|
|
180
197
|
message_history=self.messages,
|
|
181
198
|
)
|
|
182
199
|
new_messages = result.new_messages()
|
|
183
200
|
self.messages.extend(new_messages)
|
|
184
201
|
thinking_animation.stop()
|
|
185
|
-
|
|
202
|
+
usage = result.usage()
|
|
203
|
+
request_tokens = usage.request_tokens or 0
|
|
204
|
+
response_tokens = usage.response_tokens or 0
|
|
205
|
+
total_tokens = usage.total_tokens or 0
|
|
206
|
+
cost = (
|
|
207
|
+
request_tokens * model_costs["input_cost_per_token"]
|
|
208
|
+
+ response_tokens * model_costs["output_cost_per_token"]
|
|
209
|
+
)
|
|
210
|
+
click.echo()
|
|
186
211
|
click.echo(result.output)
|
|
187
212
|
click.echo("\n")
|
|
213
|
+
click.echo(f"Input tokens: {request_tokens}")
|
|
214
|
+
click.echo(f"Output tokens: {response_tokens}")
|
|
215
|
+
click.echo(f"Total tokens: {total_tokens}")
|
|
216
|
+
click.echo(f"Cost: ${cost:.6f}")
|
|
188
217
|
|
|
189
218
|
|
|
190
|
-
def run_agent(config: dict[str, Any], project: Project):
|
|
219
|
+
def run_agent(config: dict[str, Any], project: Project, dangerously_skip_permissions: bool):
|
|
191
220
|
display_banner()
|
|
192
221
|
|
|
193
222
|
try:
|
|
194
223
|
token = config["token"]
|
|
195
224
|
host = config["host"]
|
|
196
|
-
agent = TinybirdAgent(token, host, project)
|
|
225
|
+
agent = TinybirdAgent(token, host, project, dangerously_skip_permissions)
|
|
197
226
|
click.echo()
|
|
198
227
|
if config.get("token"):
|
|
199
228
|
click.echo(FeedbackManager.info(message="Describe what you want to create and I'll help you build it"))
|
|
@@ -289,3 +318,40 @@ def deploy_check_project(config: dict[str, Any], project: Project) -> None:
|
|
|
289
318
|
wait=True,
|
|
290
319
|
auto=True,
|
|
291
320
|
)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def append_data(config: dict[str, Any], datasource_name: str, path: str) -> None:
|
|
324
|
+
client = get_tinybird_local_client(config, test=False, silent=False)
|
|
325
|
+
append_mock_data(client, datasource_name, path)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def mock_data(
|
|
329
|
+
config: dict[str, Any], project: Project, datasource_name: str, data_format: str, rows: int
|
|
330
|
+
) -> list[dict[str, Any]]:
|
|
331
|
+
client = get_tinybird_local_client(config, test=False, silent=False)
|
|
332
|
+
cli_config = CLIConfig.get_project_config()
|
|
333
|
+
datasource_path = project.get_resource_path(datasource_name, "datasource")
|
|
334
|
+
|
|
335
|
+
if not datasource_path:
|
|
336
|
+
raise CLIMockException(f"Datasource {datasource_name} not found")
|
|
337
|
+
|
|
338
|
+
datasource_content = Path(datasource_path).read_text()
|
|
339
|
+
prompt = ""
|
|
340
|
+
return create_mock_data(
|
|
341
|
+
datasource_name,
|
|
342
|
+
datasource_content,
|
|
343
|
+
rows,
|
|
344
|
+
prompt,
|
|
345
|
+
cli_config,
|
|
346
|
+
config,
|
|
347
|
+
cli_config.get_user_token() or "",
|
|
348
|
+
client,
|
|
349
|
+
data_format,
|
|
350
|
+
project.folder,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def analyze_fixture(config: dict[str, Any], fixture_path: str) -> dict[str, Any]:
|
|
355
|
+
local_client = get_tinybird_local_client(config, test=False, silent=True)
|
|
356
|
+
meta, _data = _analyze(fixture_path, local_client, Path(fixture_path).suffix.lstrip("."))
|
|
357
|
+
return meta
|
|
@@ -8,7 +8,7 @@ When asked to create a plan, you MUST respond with this EXACT format and NOTHING
|
|
|
8
8
|
Plan description: [One sentence describing what will be built]
|
|
9
9
|
|
|
10
10
|
Steps:
|
|
11
|
-
1. Connection: [name] - [description]
|
|
11
|
+
1. Connection: [name] - [description]
|
|
12
12
|
2. Datasource: [name] - [description] - Depends on: [connection_name (optional)]
|
|
13
13
|
3. Endpoint: [name] - [description] - Depends on: [resources]
|
|
14
14
|
4. Materialized pipe: [name] - [description] - Depends on: [resources]
|
|
@@ -16,9 +16,15 @@ Steps:
|
|
|
16
16
|
6. Sink: [name] - [description] - Depends on: [resources]
|
|
17
17
|
7. Copy: [name] - [description] - Depends on: [resources]
|
|
18
18
|
8. Build project
|
|
19
|
+
9. Generate mock data: [datasource_name]
|
|
20
|
+
10. Append existing fixture: [fixture_pathname] - Target: [datasource_name]
|
|
19
21
|
|
|
22
|
+
<dev_notes>
|
|
20
23
|
You can skip steps where resources will not be created or updated.
|
|
21
|
-
Always add
|
|
24
|
+
Always add 'Build project' step after generating resources.
|
|
25
|
+
Always add 'Generate mock data' step after building project if a landing datasource was created.
|
|
26
|
+
Always add 'Append existing fixture' step after building project if a fixture file was provided at the beginning of the plan.
|
|
27
|
+
</dev_notes>
|
|
22
28
|
|
|
23
29
|
Resource dependencies:
|
|
24
30
|
[resource_name]: [resources]
|
|
@@ -89,31 +95,53 @@ datafile_instructions = """
|
|
|
89
95
|
|
|
90
96
|
def resources_prompt(project: Project) -> str:
|
|
91
97
|
files = project.get_project_files()
|
|
98
|
+
fixture_files = project.get_fixture_files()
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
""
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
100
|
+
resources_content = "# Existing resources in the project:\n"
|
|
101
|
+
if files:
|
|
102
|
+
paths = [Path(file_path) for file_path in files]
|
|
103
|
+
|
|
104
|
+
resources_content += "\n".join(
|
|
105
|
+
[
|
|
106
|
+
f"""
|
|
107
|
+
<resource>
|
|
108
|
+
<path>{file_path.relative_to(project.folder)}</path>
|
|
109
|
+
<type>{get_resource_type(file_path)}</type>
|
|
110
|
+
<name>{file_path.stem}</name>
|
|
111
|
+
<content>{file_path.read_text()}</content>
|
|
112
|
+
</resource>
|
|
113
|
+
"""
|
|
114
|
+
for file_path in paths
|
|
115
|
+
]
|
|
116
|
+
)
|
|
117
|
+
else:
|
|
118
|
+
resources_content += "No resources found"
|
|
119
|
+
|
|
120
|
+
fixture_content = "# Fixture files in the project:\n"
|
|
121
|
+
if fixture_files:
|
|
122
|
+
paths = [Path(file_path) for file_path in fixture_files]
|
|
123
|
+
fixture_content += "\n".join(
|
|
124
|
+
[
|
|
125
|
+
f"""
|
|
126
|
+
<fixture>
|
|
127
|
+
<path>{file_path.relative_to(project.folder)}</path>
|
|
128
|
+
<name>{file_path.stem}</name>
|
|
129
|
+
</fixture>
|
|
130
|
+
"""
|
|
131
|
+
for file_path in paths
|
|
132
|
+
]
|
|
133
|
+
)
|
|
134
|
+
else:
|
|
135
|
+
fixture_content += "No fixture files found"
|
|
136
|
+
|
|
137
|
+
return resources_content + "\n" + fixture_content
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_resource_type(path: Path) -> str:
|
|
141
|
+
if path.suffix.lower() == ".pipe":
|
|
142
|
+
return Project.get_pipe_type(str(path))
|
|
143
|
+
elif path.suffix.lower() == ".datasource":
|
|
144
|
+
return "datasource"
|
|
145
|
+
elif path.suffix.lower() == ".connection":
|
|
146
|
+
return "connection"
|
|
147
|
+
return "unknown"
|
|
@@ -0,0 +1,55 @@
|
|
|
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_append_confirmation(datasource_name: str) -> bool:
|
|
9
|
+
"""Get user confirmation for appending existing fixture"""
|
|
10
|
+
while True:
|
|
11
|
+
result = show_options(
|
|
12
|
+
options=["Yes, append existing fixture", "No, and tell Tinybird Code what to do"],
|
|
13
|
+
title=f"Do you want to append existing fixture for datasource {datasource_name}?",
|
|
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 append(ctx: RunContext[TinybirdAgentContext], datasource_name: str, fixture_pathname: str) -> str:
|
|
28
|
+
"""Append existing fixture to a datasource
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
datasource_name: Name of the datasource to append fixture to
|
|
32
|
+
fixture_pathname: Path to the fixture file to append
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
str: Message indicating the success or failure of the appending
|
|
36
|
+
"""
|
|
37
|
+
try:
|
|
38
|
+
ctx.deps.thinking_animation.stop()
|
|
39
|
+
confirmation = ctx.deps.dangerously_skip_permissions or get_append_confirmation(datasource_name)
|
|
40
|
+
ctx.deps.thinking_animation.start()
|
|
41
|
+
|
|
42
|
+
if not confirmation:
|
|
43
|
+
return "User rejected appending existing fixture. Skipping..."
|
|
44
|
+
|
|
45
|
+
ctx.deps.thinking_animation.stop()
|
|
46
|
+
click.echo(FeedbackManager.highlight(message=f"\n» Appending {fixture_pathname} to {datasource_name}..."))
|
|
47
|
+
ctx.deps.append_data(datasource_name=datasource_name, path=fixture_pathname)
|
|
48
|
+
click.echo(FeedbackManager.success(message=f"✓ Data appended to {datasource_name}"))
|
|
49
|
+
ctx.deps.thinking_animation.start()
|
|
50
|
+
return f"Data appended to {datasource_name}"
|
|
51
|
+
except Exception as e:
|
|
52
|
+
ctx.deps.thinking_animation.stop()
|
|
53
|
+
click.echo(FeedbackManager.error(message=e))
|
|
54
|
+
ctx.deps.thinking_animation.start()
|
|
55
|
+
return f"Error appending fixture {fixture_pathname} to {datasource_name}: {e}"
|
|
@@ -9,6 +9,7 @@ def build(ctx: RunContext[TinybirdAgentContext]) -> str:
|
|
|
9
9
|
"""Build the project"""
|
|
10
10
|
try:
|
|
11
11
|
ctx.deps.thinking_animation.stop()
|
|
12
|
+
click.echo(FeedbackManager.highlight(message="\n» Building project..."))
|
|
12
13
|
ctx.deps.build_project(test=False, silent=False)
|
|
13
14
|
ctx.deps.thinking_animation.start()
|
|
14
15
|
return "Project built successfully"
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import difflib
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
from colorama import Back, Fore, Style, init
|
|
6
|
+
|
|
7
|
+
init()
|
|
8
|
+
except ImportError: # fallback so that the imported classes always exist
|
|
9
|
+
|
|
10
|
+
class ColorFallback:
|
|
11
|
+
def __getattr__(self, name):
|
|
12
|
+
return ""
|
|
13
|
+
|
|
14
|
+
Fore = Back = Style = ColorFallback()
|
|
15
|
+
|
|
16
|
+
import click
|
|
17
|
+
from pydantic_ai import RunContext
|
|
18
|
+
|
|
19
|
+
from tinybird.tb.modules.agent.utils import Datafile, TinybirdAgentContext, show_options
|
|
20
|
+
from tinybird.tb.modules.exceptions import CLIBuildException
|
|
21
|
+
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def create_line_numbered_diff(original_content: str, new_content: str, filename: str) -> str:
|
|
25
|
+
"""Create a diff with line numbers similar to the example format"""
|
|
26
|
+
original_lines = original_content.splitlines()
|
|
27
|
+
new_lines = new_content.splitlines()
|
|
28
|
+
|
|
29
|
+
# Create a SequenceMatcher to find the differences
|
|
30
|
+
matcher = difflib.SequenceMatcher(None, original_lines, new_lines)
|
|
31
|
+
|
|
32
|
+
result = []
|
|
33
|
+
result.append(f"╭{'─' * 88}╮")
|
|
34
|
+
result.append(f"│ {filename:<86} │")
|
|
35
|
+
result.append(f"│{' ' * 88}│")
|
|
36
|
+
|
|
37
|
+
# Process the opcodes to build the diff
|
|
38
|
+
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
|
|
39
|
+
if tag == "equal":
|
|
40
|
+
# Show context lines
|
|
41
|
+
for i, line in enumerate(original_lines[i1:i2]):
|
|
42
|
+
line_num = i1 + i + 1
|
|
43
|
+
result.append(f"│ {line_num:4} {line:<74} │")
|
|
44
|
+
elif tag == "replace":
|
|
45
|
+
# Show removed lines
|
|
46
|
+
for i, line in enumerate(original_lines[i1:i2]):
|
|
47
|
+
line_num = i1 + i + 1
|
|
48
|
+
result.append(f"│ {Back.RED}{line_num:4} - {line:<74}{Back.RESET} │")
|
|
49
|
+
# Show added lines
|
|
50
|
+
for i, line in enumerate(new_lines[j1:j2]):
|
|
51
|
+
line_num = i1 + i + 1
|
|
52
|
+
result.append(f"│ {Back.GREEN}{line_num:4} + {line:<74}{Back.RESET} │")
|
|
53
|
+
elif tag == "delete":
|
|
54
|
+
# Show removed lines
|
|
55
|
+
for i, line in enumerate(original_lines[i1:i2]):
|
|
56
|
+
line_num = i1 + i + 1
|
|
57
|
+
result.append(f"│ {Back.RED}{line_num:4} - {line:<74}{Back.RESET} │")
|
|
58
|
+
elif tag == "insert":
|
|
59
|
+
# Show added lines
|
|
60
|
+
for i, line in enumerate(new_lines[j1:j2]):
|
|
61
|
+
# Use the line number from the original position
|
|
62
|
+
line_num = i1 + i + 1
|
|
63
|
+
result.append(f"│ {Back.GREEN}{line_num:4} + {line:<74}{Back.RESET} │")
|
|
64
|
+
|
|
65
|
+
result.append(f"╰{'─' * 88}╯")
|
|
66
|
+
return "\n".join(result)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def create_line_numbered_content(content: str, filename: str) -> str:
|
|
70
|
+
"""Create a formatted display of file content with line numbers"""
|
|
71
|
+
lines = content.splitlines()
|
|
72
|
+
|
|
73
|
+
result = []
|
|
74
|
+
result.append(f"╭{'─' * 88}╮")
|
|
75
|
+
result.append(f"│ {filename:<86} │")
|
|
76
|
+
result.append(f"│{' ' * 88}│")
|
|
77
|
+
|
|
78
|
+
for i, line in enumerate(lines, 1):
|
|
79
|
+
result.append(f"│ {i:4} {line:<74} │")
|
|
80
|
+
|
|
81
|
+
result.append(f"╰{'─' * 88}╯")
|
|
82
|
+
return "\n".join(result)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def get_resource_confirmation(resource: Datafile, exists: bool) -> bool:
|
|
86
|
+
"""Get user confirmation for creating a resource"""
|
|
87
|
+
while True:
|
|
88
|
+
action = "create" if not exists else "update"
|
|
89
|
+
result = show_options(
|
|
90
|
+
options=[f"Yes, {action} {resource.type} '{resource.name}'", "No, and tell Tinybird Code what to do"],
|
|
91
|
+
title=f"What would you like to do with {resource.type} '{resource.name}'?",
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
if result is None: # Cancelled
|
|
95
|
+
return False
|
|
96
|
+
|
|
97
|
+
if result.startswith("Yes"):
|
|
98
|
+
return True
|
|
99
|
+
elif result.startswith("No"):
|
|
100
|
+
return False
|
|
101
|
+
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def create_datafile(ctx: RunContext[TinybirdAgentContext], resource: Datafile) -> str:
|
|
106
|
+
"""Given a resource representation, create a file in the project folder
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
resource (Datafile): The resource to create. Required.
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
str: If the resource was created or not.
|
|
113
|
+
"""
|
|
114
|
+
try:
|
|
115
|
+
ctx.deps.thinking_animation.stop()
|
|
116
|
+
resource.pathname = resource.pathname.removeprefix("/")
|
|
117
|
+
path = Path(ctx.deps.folder) / resource.pathname
|
|
118
|
+
content = resource.content
|
|
119
|
+
exists = str(path) in ctx.deps.get_project_files()
|
|
120
|
+
if exists:
|
|
121
|
+
content = create_line_numbered_diff(path.read_text(), resource.content, resource.pathname)
|
|
122
|
+
else:
|
|
123
|
+
content = create_line_numbered_content(resource.content, resource.pathname)
|
|
124
|
+
click.echo(content)
|
|
125
|
+
confirmation = ctx.deps.dangerously_skip_permissions or get_resource_confirmation(resource, exists)
|
|
126
|
+
|
|
127
|
+
if not confirmation:
|
|
128
|
+
ctx.deps.thinking_animation.start()
|
|
129
|
+
return f"Resource {resource.pathname} was not created. User cancelled creation."
|
|
130
|
+
|
|
131
|
+
folder_path = path.parent
|
|
132
|
+
folder_path.mkdir(parents=True, exist_ok=True)
|
|
133
|
+
path.touch(exist_ok=True)
|
|
134
|
+
path.write_text(resource.content)
|
|
135
|
+
ctx.deps.build_project(test=True, silent=True)
|
|
136
|
+
ctx.deps.thinking_animation.start()
|
|
137
|
+
return f"Created {resource.pathname}"
|
|
138
|
+
|
|
139
|
+
except CLIBuildException as e:
|
|
140
|
+
ctx.deps.thinking_animation.stop()
|
|
141
|
+
click.echo(FeedbackManager.error(message=e))
|
|
142
|
+
ctx.deps.thinking_animation.start()
|
|
143
|
+
return f"Error building project: {e}"
|
|
144
|
+
except Exception as e:
|
|
145
|
+
return f"Error creating {resource.pathname}: {e}"
|
|
@@ -28,7 +28,7 @@ def deploy(ctx: RunContext[TinybirdAgentContext]) -> str:
|
|
|
28
28
|
"""Deploy the project"""
|
|
29
29
|
try:
|
|
30
30
|
ctx.deps.thinking_animation.stop()
|
|
31
|
-
confirmation = get_deploy_confirmation()
|
|
31
|
+
confirmation = ctx.deps.dangerously_skip_permissions or get_deploy_confirmation()
|
|
32
32
|
ctx.deps.thinking_animation.start()
|
|
33
33
|
|
|
34
34
|
if not confirmation:
|
|
@@ -0,0 +1,59 @@
|
|
|
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.datafile.fixture import persist_fixture
|
|
6
|
+
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_mock_confirmation(datasource_name: str) -> bool:
|
|
10
|
+
"""Get user confirmation for creating mock data"""
|
|
11
|
+
while True:
|
|
12
|
+
result = show_options(
|
|
13
|
+
options=["Yes, create mock data", "No, and tell Tinybird Code what to do"],
|
|
14
|
+
title=f"Do you want to generate mock data for datasource {datasource_name}?",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
if result is None: # Cancelled
|
|
18
|
+
return False
|
|
19
|
+
|
|
20
|
+
if result.startswith("Yes"):
|
|
21
|
+
return True
|
|
22
|
+
elif result.startswith("No"):
|
|
23
|
+
return False
|
|
24
|
+
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def mock(ctx: RunContext[TinybirdAgentContext], datasource_name: str, data_format: str, rows: int) -> str:
|
|
29
|
+
"""Create mock data for a datasource
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
datasource_name: Name of the datasource to create mock data for
|
|
33
|
+
data_format: Format of the mock data to create. Options: ndjson, csv
|
|
34
|
+
rows: Number of rows to create. If not provided, the default is 10
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
str: Message indicating the success or failure of the mock data generation
|
|
38
|
+
"""
|
|
39
|
+
try:
|
|
40
|
+
ctx.deps.thinking_animation.stop()
|
|
41
|
+
confirmation = ctx.deps.dangerously_skip_permissions or get_mock_confirmation(datasource_name)
|
|
42
|
+
ctx.deps.thinking_animation.start()
|
|
43
|
+
|
|
44
|
+
if not confirmation:
|
|
45
|
+
return "User rejected mock data generation. Skipping..."
|
|
46
|
+
|
|
47
|
+
ctx.deps.thinking_animation.stop()
|
|
48
|
+
click.echo(FeedbackManager.highlight(message=f"\n» Generating mock data for {datasource_name}..."))
|
|
49
|
+
data = ctx.deps.mock_data(datasource_name=datasource_name, data_format=data_format, rows=rows)
|
|
50
|
+
fixture_path = persist_fixture(datasource_name, data, ctx.deps.folder, format=data_format)
|
|
51
|
+
ctx.deps.append_data(datasource_name=datasource_name, path=str(fixture_path))
|
|
52
|
+
click.echo(FeedbackManager.success(message=f"✓ Data generated for {datasource_name}"))
|
|
53
|
+
ctx.deps.thinking_animation.start()
|
|
54
|
+
return f"Mock data generated successfully for datasource {datasource_name}"
|
|
55
|
+
except Exception as e:
|
|
56
|
+
ctx.deps.thinking_animation.stop()
|
|
57
|
+
click.echo(FeedbackManager.error(message=e))
|
|
58
|
+
ctx.deps.thinking_animation.start()
|
|
59
|
+
return f"Error generating mock data: {e}"
|
|
@@ -35,7 +35,7 @@ def plan(ctx: RunContext[TinybirdAgentContext], plan: str) -> str:
|
|
|
35
35
|
try:
|
|
36
36
|
ctx.deps.thinking_animation.stop()
|
|
37
37
|
click.echo(plan)
|
|
38
|
-
confirmation = get_plan_confirmation()
|
|
38
|
+
confirmation = ctx.deps.dangerously_skip_permissions or get_plan_confirmation()
|
|
39
39
|
ctx.deps.thinking_animation.start()
|
|
40
40
|
|
|
41
41
|
if not confirmation:
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from pydantic_ai import RunContext
|
|
5
|
+
|
|
6
|
+
from tinybird.tb.modules.agent.utils import TinybirdAgentContext
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def read_fixture_data(ctx: RunContext[TinybirdAgentContext], fixture_pathname: str):
|
|
10
|
+
"""Read fixture data in the project folder
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
fixture_pathname (str): a path to a fixture file. Required.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
str: The content of the fixture data file.
|
|
17
|
+
"""
|
|
18
|
+
fixture_path = Path(ctx.deps.folder) / fixture_pathname.lstrip("/")
|
|
19
|
+
|
|
20
|
+
if not fixture_path.exists():
|
|
21
|
+
return f"No fixture data found for {fixture_pathname}. Please check the name of the fixture and try again."
|
|
22
|
+
|
|
23
|
+
response = ctx.deps.analyze_fixture(fixture_path=str(fixture_path))
|
|
24
|
+
# limit content to first 10 rows
|
|
25
|
+
data = response["preview"]["data"][:10]
|
|
26
|
+
schema = response["analysis"]["schema"]
|
|
27
|
+
|
|
28
|
+
return f"#Result of analysis of {fixture_pathname}:\n##Data sample:\n{json.dumps(data)}\n##Schema:\n{schema}"
|
|
@@ -26,6 +26,10 @@ class TinybirdAgentContext(BaseModel):
|
|
|
26
26
|
build_project: Callable[..., None]
|
|
27
27
|
deploy_project: Callable[[], None]
|
|
28
28
|
deploy_check_project: Callable[[], None]
|
|
29
|
+
mock_data: Callable[..., list[dict[str, Any]]]
|
|
30
|
+
append_data: Callable[..., None]
|
|
31
|
+
analyze_fixture: Callable[..., dict[str, Any]]
|
|
32
|
+
dangerously_skip_permissions: bool
|
|
29
33
|
|
|
30
34
|
|
|
31
35
|
default_style = Style.from_dict(
|
|
@@ -3,7 +3,7 @@ import time
|
|
|
3
3
|
from copy import deepcopy
|
|
4
4
|
from functools import partial
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Callable, List
|
|
6
|
+
from typing import Any, Callable, Dict, List
|
|
7
7
|
from urllib.parse import urlencode
|
|
8
8
|
|
|
9
9
|
import click
|
|
@@ -32,8 +32,11 @@ def build(ctx: click.Context, watch: bool) -> None:
|
|
|
32
32
|
"""
|
|
33
33
|
Validate and build the project server side.
|
|
34
34
|
"""
|
|
35
|
+
obj: Dict[str, Any] = ctx.ensure_object(dict)
|
|
35
36
|
project: Project = ctx.ensure_object(dict)["project"]
|
|
36
37
|
tb_client: TinyB = ctx.ensure_object(dict)["client"]
|
|
38
|
+
if obj["env"] == "cloud":
|
|
39
|
+
raise click.ClickException(FeedbackManager.error_build_only_supported_in_local())
|
|
37
40
|
|
|
38
41
|
if project.has_deeper_level():
|
|
39
42
|
click.echo(
|