synth-ai 0.2.13.dev2__py3-none-any.whl → 0.2.16__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 synth-ai might be problematic. Click here for more details.
- examples/README.md +1 -0
- examples/multi_step/SFT_README.md +147 -0
- examples/multi_step/configs/README_verilog_rl.md +77 -0
- examples/multi_step/configs/VERILOG_REWARDS.md +90 -0
- examples/multi_step/configs/VERILOG_RL_CHECKLIST.md +183 -0
- examples/multi_step/configs/crafter_eval_synth_qwen4b.toml +35 -0
- examples/multi_step/configs/crafter_eval_text_only_groq_qwen32b.toml +36 -0
- examples/multi_step/configs/crafter_rl_stepwise_hosted_judge.toml +12 -11
- examples/multi_step/configs/crafter_sft_qwen30b_lora.toml +62 -0
- examples/multi_step/configs/crafter_synth_backend.md +40 -0
- examples/multi_step/configs/verilog_eval_groq_qwen32b.toml +31 -0
- examples/multi_step/configs/verilog_eval_synth_qwen8b.toml +33 -0
- examples/multi_step/configs/verilog_rl_lora.toml +190 -0
- examples/multi_step/convert_traces_to_sft.py +84 -0
- examples/multi_step/judges/crafter_backend_judge.py +220 -0
- examples/multi_step/judges/verilog_backend_judge.py +234 -0
- examples/multi_step/readme.md +48 -0
- examples/multi_step/run_sft_qwen30b.sh +45 -0
- examples/multi_step/verilog_rl_lora.md +218 -0
- examples/qwen_coder/configs/coder_lora_30b.toml +3 -2
- examples/qwen_coder/configs/coder_lora_4b.toml +2 -1
- examples/qwen_coder/configs/coder_lora_small.toml +2 -1
- examples/qwen_vl/BUGS_AND_FIXES.md +232 -0
- examples/qwen_vl/IMAGE_VALIDATION_COMPLETE.md +271 -0
- examples/qwen_vl/IMAGE_VALIDATION_SUMMARY.md +260 -0
- examples/qwen_vl/INFERENCE_SFT_TESTS.md +412 -0
- examples/qwen_vl/NEXT_STEPS_2B.md +325 -0
- examples/qwen_vl/QUICKSTART.md +327 -0
- examples/qwen_vl/QUICKSTART_RL_VISION.md +110 -0
- examples/qwen_vl/README.md +154 -0
- examples/qwen_vl/RL_VISION_COMPLETE.md +475 -0
- examples/qwen_vl/RL_VISION_TESTING.md +333 -0
- examples/qwen_vl/SDK_VISION_INTEGRATION.md +328 -0
- examples/qwen_vl/SETUP_COMPLETE.md +275 -0
- examples/qwen_vl/VISION_TESTS_COMPLETE.md +490 -0
- examples/qwen_vl/VLM_PIPELINE_COMPLETE.md +242 -0
- examples/qwen_vl/__init__.py +2 -0
- examples/qwen_vl/collect_data_via_cli.md +423 -0
- examples/qwen_vl/collect_vision_traces.py +368 -0
- examples/qwen_vl/configs/crafter_rl_vision_qwen3vl4b.toml +127 -0
- examples/qwen_vl/configs/crafter_vlm_sft_example.toml +60 -0
- examples/qwen_vl/configs/eval_gpt4o_mini_vision.toml +43 -0
- examples/qwen_vl/configs/eval_gpt4o_vision_proper.toml +29 -0
- examples/qwen_vl/configs/eval_gpt5nano_vision.toml +45 -0
- examples/qwen_vl/configs/eval_qwen2vl_vision.toml +44 -0
- examples/qwen_vl/configs/filter_qwen2vl_sft.toml +50 -0
- examples/qwen_vl/configs/filter_vision_sft.toml +53 -0
- examples/qwen_vl/configs/filter_vision_test.toml +8 -0
- examples/qwen_vl/configs/sft_qwen3_vl_2b_test.toml +54 -0
- examples/qwen_vl/crafter_gpt5nano_agent.py +308 -0
- examples/qwen_vl/crafter_qwen_vl_agent.py +300 -0
- examples/qwen_vl/run_vision_comparison.sh +62 -0
- examples/qwen_vl/run_vision_sft_pipeline.sh +175 -0
- examples/qwen_vl/test_image_validation.py +201 -0
- examples/qwen_vl/test_sft_vision_data.py +110 -0
- examples/rl/README.md +1 -1
- examples/rl/configs/eval_base_qwen.toml +17 -0
- examples/rl/configs/eval_rl_qwen.toml +13 -0
- examples/rl/configs/rl_from_base_qwen.toml +37 -0
- examples/rl/configs/rl_from_base_qwen17.toml +76 -0
- examples/rl/configs/rl_from_ft_qwen.toml +37 -0
- examples/rl/run_eval.py +436 -0
- examples/rl/run_rl_and_save.py +111 -0
- examples/rl/task_app/README.md +22 -0
- examples/rl/task_app/math_single_step.py +990 -0
- examples/rl/task_app/math_task_app.py +111 -0
- examples/sft/README.md +5 -5
- examples/sft/configs/crafter_fft_qwen0p6b.toml +4 -2
- examples/sft/configs/crafter_lora_qwen0p6b.toml +4 -3
- examples/sft/evaluate.py +4 -4
- examples/sft/export_dataset.py +7 -4
- examples/sft/generate_traces.py +2 -0
- examples/swe/task_app/README.md +1 -1
- examples/swe/task_app/grpo_swe_mini.py +1 -1
- examples/swe/task_app/grpo_swe_mini_task_app.py +0 -12
- examples/swe/task_app/hosted/envs/mini_swe/environment.py +13 -13
- examples/swe/task_app/hosted/policy_routes.py +0 -2
- examples/swe/task_app/hosted/rollout.py +2 -8
- examples/task_apps/IMAGE_ONLY_EVAL_QUICKSTART.md +258 -0
- examples/task_apps/crafter/CREATE_SFT_DATASET.md +273 -0
- examples/task_apps/crafter/EVAL_IMAGE_ONLY_RESULTS.md +152 -0
- examples/task_apps/crafter/FILTER_COMMAND_STATUS.md +174 -0
- examples/task_apps/crafter/FILTER_COMMAND_SUCCESS.md +268 -0
- examples/task_apps/crafter/QUERY_EXAMPLES.md +203 -0
- examples/task_apps/crafter/README_IMAGE_ONLY_EVAL.md +316 -0
- examples/task_apps/crafter/eval_image_only_gpt4o.toml +28 -0
- examples/task_apps/crafter/eval_text_only_groq_llama.toml +36 -0
- examples/task_apps/crafter/filter_sft_dataset.toml +16 -0
- examples/task_apps/crafter/task_app/__init__.py +3 -0
- examples/task_apps/crafter/task_app/grpo_crafter.py +309 -14
- examples/task_apps/crafter/task_app/synth_envs_hosted/envs/crafter/environment.py +10 -0
- examples/task_apps/crafter/task_app/synth_envs_hosted/envs/crafter/policy.py +75 -4
- examples/task_apps/crafter/task_app/synth_envs_hosted/envs/crafter/react_agent.py +17 -2
- examples/task_apps/crafter/task_app/synth_envs_hosted/inference/openai_client.py +55 -3
- examples/task_apps/crafter/task_app/synth_envs_hosted/policy_routes.py +114 -32
- examples/task_apps/crafter/task_app/synth_envs_hosted/rollout.py +127 -27
- examples/task_apps/crafter/task_app/synth_envs_hosted/utils.py +156 -0
- examples/task_apps/enron/__init__.py +1 -0
- examples/task_apps/enron/filter_sft.toml +5 -0
- examples/task_apps/enron/tests/__init__.py +2 -0
- examples/task_apps/enron/tests/integration/__init__.py +2 -0
- examples/task_apps/enron/tests/integration/test_enron_eval.py +2 -0
- examples/task_apps/enron/tests/unit/__init__.py +2 -0
- examples/task_apps/pokemon_red/EVAL_IMAGE_ONLY_COMPLETE.md +283 -0
- examples/task_apps/pokemon_red/EVAL_IMAGE_ONLY_STATUS.md +155 -0
- examples/task_apps/pokemon_red/README_IMAGE_ONLY_EVAL.md +415 -0
- examples/task_apps/pokemon_red/eval_image_only_gpt4o.toml +29 -0
- examples/task_apps/pokemon_red/pallet_town_rl_config.toml +2 -0
- examples/task_apps/pokemon_red/task_app.py +199 -6
- examples/task_apps/pokemon_red/test_pallet_town_rewards.py +2 -0
- examples/task_apps/sokoban/filter_sft.toml +5 -0
- examples/task_apps/sokoban/tests/__init__.py +2 -0
- examples/task_apps/sokoban/tests/integration/__init__.py +2 -0
- examples/task_apps/sokoban/tests/unit/__init__.py +2 -0
- examples/task_apps/verilog/eval_groq_qwen32b.toml +8 -4
- examples/task_apps/verilog/filter_sft.toml +5 -0
- examples/task_apps/verilog/task_app/grpo_verilog.py +258 -23
- examples/task_apps/verilog/tests/__init__.py +2 -0
- examples/task_apps/verilog/tests/integration/__init__.py +2 -0
- examples/task_apps/verilog/tests/integration/test_verilog_eval.py +2 -0
- examples/task_apps/verilog/tests/unit/__init__.py +2 -0
- examples/vlm/README.md +3 -3
- examples/vlm/configs/crafter_vlm_gpt4o.toml +2 -0
- examples/vlm/crafter_openai_vlm_agent.py +3 -5
- examples/vlm/filter_image_rows.py +1 -1
- examples/vlm/run_crafter_vlm_benchmark.py +2 -2
- examples/warming_up_to_rl/_utils.py +92 -0
- examples/warming_up_to_rl/analyze_trace_db.py +1 -1
- examples/warming_up_to_rl/configs/crafter_fft.toml +2 -0
- examples/warming_up_to_rl/configs/crafter_fft_4b.toml +2 -0
- examples/warming_up_to_rl/configs/eval_fft_qwen4b.toml +2 -0
- examples/warming_up_to_rl/configs/eval_groq_qwen32b.toml +2 -0
- examples/warming_up_to_rl/configs/eval_modal_qwen4b.toml +2 -1
- examples/warming_up_to_rl/configs/rl_from_base_qwen4b.toml +2 -1
- examples/warming_up_to_rl/configs/rl_from_ft.toml +2 -0
- examples/warming_up_to_rl/export_trace_sft.py +174 -60
- examples/warming_up_to_rl/groq_test.py +2 -0
- examples/warming_up_to_rl/readme.md +63 -132
- examples/warming_up_to_rl/run_fft_and_save.py +1 -1
- examples/warming_up_to_rl/run_local_rollout.py +2 -0
- examples/warming_up_to_rl/run_local_rollout_modal.py +2 -0
- examples/warming_up_to_rl/run_local_rollout_parallel.py +2 -0
- examples/warming_up_to_rl/run_local_rollout_traced.py +2 -0
- examples/warming_up_to_rl/run_rl_and_save.py +1 -1
- examples/warming_up_to_rl/run_rollout_remote.py +2 -0
- examples/warming_up_to_rl/task_app/README.md +42 -0
- examples/warming_up_to_rl/task_app/grpo_crafter.py +696 -0
- examples/warming_up_to_rl/task_app/grpo_crafter_task_app.py +135 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/README.md +173 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/__init__.py +5 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/branching.py +143 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/environment_routes.py +1226 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/__init__.py +1 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/crafter/__init__.py +6 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/crafter/app.py +1 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/crafter/environment.py +522 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/crafter/policy.py +478 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/crafter/react_agent.py +108 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/crafter/shared.py +305 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/envs/crafter/tools.py +47 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/hosted_app.py +204 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/inference/__init__.py +5 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/inference/openai_client.py +618 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/main.py +100 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/policy_routes.py +1081 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/registry.py +195 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/rollout.py +1861 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/storage/__init__.py +5 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/storage/volume.py +211 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/test_agents.py +161 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/test_service.py +137 -0
- examples/warming_up_to_rl/task_app/synth_envs_hosted/utils.py +62 -0
- synth_ai/__init__.py +44 -30
- synth_ai/_utils/__init__.py +47 -0
- synth_ai/_utils/base_url.py +10 -0
- synth_ai/_utils/http.py +10 -0
- synth_ai/_utils/prompts.py +10 -0
- synth_ai/_utils/task_app_state.py +12 -0
- synth_ai/_utils/user_config.py +10 -0
- synth_ai/api/models/supported.py +145 -7
- synth_ai/api/train/__init__.py +13 -1
- synth_ai/api/train/cli.py +30 -7
- synth_ai/api/train/config_finder.py +18 -11
- synth_ai/api/train/env_resolver.py +13 -10
- synth_ai/cli/__init__.py +66 -49
- synth_ai/cli/_modal_wrapper.py +9 -6
- synth_ai/cli/_typer_patch.py +0 -2
- synth_ai/cli/_validate_task_app.py +22 -4
- synth_ai/cli/legacy_root_backup.py +3 -1
- synth_ai/cli/lib/__init__.py +10 -0
- synth_ai/cli/lib/task_app_discovery.py +7 -0
- synth_ai/cli/lib/task_app_env.py +518 -0
- synth_ai/cli/recent.py +1 -0
- synth_ai/cli/setup.py +266 -0
- synth_ai/cli/task_app_deploy.py +16 -0
- synth_ai/cli/task_app_list.py +25 -0
- synth_ai/cli/task_app_modal_serve.py +16 -0
- synth_ai/cli/task_app_serve.py +18 -0
- synth_ai/cli/task_apps.py +392 -141
- synth_ai/cli/train.py +18 -0
- synth_ai/cli/tui.py +62 -0
- synth_ai/demos/__init__.py +10 -0
- synth_ai/demos/core/__init__.py +28 -1
- synth_ai/demos/crafter/__init__.py +1 -0
- synth_ai/demos/crafter/crafter_fft_4b.toml +55 -0
- synth_ai/demos/crafter/grpo_crafter_task_app.py +185 -0
- synth_ai/demos/crafter/rl_from_base_qwen4b.toml +74 -0
- synth_ai/demos/demo_registry.py +176 -0
- synth_ai/demos/demo_task_apps/crafter/grpo_crafter_task_app.py +1 -1
- synth_ai/demos/math/__init__.py +1 -0
- synth_ai/demos/math/_common.py +16 -0
- synth_ai/demos/math/app.py +38 -0
- synth_ai/demos/math/config.toml +76 -0
- synth_ai/demos/math/deploy_modal.py +54 -0
- synth_ai/demos/math/modal_task_app.py +702 -0
- synth_ai/demos/math/task_app_entry.py +51 -0
- synth_ai/environments/environment/core.py +7 -1
- synth_ai/environments/examples/bandit/engine.py +0 -1
- synth_ai/environments/examples/bandit/environment.py +0 -1
- synth_ai/environments/examples/crafter_classic/environment.py +1 -1
- synth_ai/environments/examples/verilog/engine.py +76 -10
- synth_ai/environments/examples/wordle/environment.py +0 -1
- synth_ai/evals/base.py +16 -5
- synth_ai/evals/client.py +1 -1
- synth_ai/inference/client.py +1 -1
- synth_ai/learning/client.py +1 -1
- synth_ai/learning/health.py +1 -1
- synth_ai/learning/jobs.py +1 -1
- synth_ai/learning/rl/client.py +1 -1
- synth_ai/learning/rl/env_keys.py +1 -1
- synth_ai/learning/rl/secrets.py +1 -1
- synth_ai/learning/sft/client.py +1 -1
- synth_ai/learning/sft/data.py +407 -4
- synth_ai/learning/validators.py +4 -1
- synth_ai/task/__init__.py +11 -1
- synth_ai/task/apps/__init__.py +5 -2
- synth_ai/task/config.py +259 -0
- synth_ai/task/contracts.py +15 -2
- synth_ai/task/rubrics/__init__.py +4 -2
- synth_ai/task/rubrics/loaders.py +27 -4
- synth_ai/task/rubrics/scoring.py +3 -0
- synth_ai/task/rubrics.py +219 -0
- synth_ai/task/trace_correlation_helpers.py +328 -0
- synth_ai/task/tracing_utils.py +14 -3
- synth_ai/task/validators.py +145 -2
- synth_ai/tracing_v3/config.py +15 -13
- synth_ai/tracing_v3/constants.py +21 -0
- synth_ai/tracing_v3/db_config.py +3 -1
- synth_ai/tracing_v3/decorators.py +10 -7
- synth_ai/tracing_v3/session_tracer.py +10 -0
- synth_ai/tracing_v3/turso/daemon.py +2 -2
- synth_ai/tracing_v3/turso/native_manager.py +108 -77
- synth_ai/tracing_v3/utils.py +1 -1
- synth_ai/tui/__init__.py +5 -0
- synth_ai/tui/__main__.py +13 -0
- synth_ai/tui/cli/__init__.py +1 -0
- synth_ai/tui/cli/query_experiments.py +164 -0
- synth_ai/tui/cli/query_experiments_v3.py +164 -0
- synth_ai/tui/dashboard.py +911 -0
- synth_ai/utils/__init__.py +101 -0
- synth_ai/utils/base_url.py +94 -0
- synth_ai/utils/cli.py +131 -0
- synth_ai/utils/env.py +287 -0
- synth_ai/utils/http.py +169 -0
- synth_ai/utils/modal.py +308 -0
- synth_ai/utils/process.py +212 -0
- synth_ai/utils/prompts.py +39 -0
- synth_ai/utils/sqld.py +122 -0
- synth_ai/utils/task_app_discovery.py +882 -0
- synth_ai/utils/task_app_env.py +186 -0
- synth_ai/utils/task_app_state.py +318 -0
- synth_ai/utils/user_config.py +137 -0
- synth_ai/v0/config/__init__.py +1 -5
- synth_ai/v0/config/base_url.py +1 -7
- synth_ai/v0/tracing/config.py +1 -1
- synth_ai/v0/tracing/decorators.py +1 -1
- synth_ai/v0/tracing/upload.py +1 -1
- synth_ai/v0/tracing_v1/config.py +1 -1
- synth_ai/v0/tracing_v1/decorators.py +1 -1
- synth_ai/v0/tracing_v1/upload.py +1 -1
- {synth_ai-0.2.13.dev2.dist-info → synth_ai-0.2.16.dist-info}/METADATA +85 -31
- {synth_ai-0.2.13.dev2.dist-info → synth_ai-0.2.16.dist-info}/RECORD +286 -135
- synth_ai/cli/man.py +0 -106
- synth_ai/compound/cais.py +0 -0
- synth_ai/core/experiment.py +0 -13
- synth_ai/core/system.py +0 -15
- synth_ai/demo_registry.py +0 -295
- synth_ai/handshake.py +0 -109
- synth_ai/http.py +0 -26
- {synth_ai-0.2.13.dev2.dist-info → synth_ai-0.2.16.dist-info}/WHEEL +0 -0
- {synth_ai-0.2.13.dev2.dist-info → synth_ai-0.2.16.dist-info}/entry_points.txt +0 -0
- {synth_ai-0.2.13.dev2.dist-info → synth_ai-0.2.16.dist-info}/licenses/LICENSE +0 -0
- {synth_ai-0.2.13.dev2.dist-info → synth_ai-0.2.16.dist-info}/top_level.txt +0 -0
synth_ai/cli/setup.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import contextlib
|
|
4
|
+
import os
|
|
5
|
+
import time
|
|
6
|
+
import webbrowser
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, cast
|
|
9
|
+
from urllib.parse import urljoin, urlsplit, urlunsplit
|
|
10
|
+
|
|
11
|
+
import requests
|
|
12
|
+
from click.exceptions import Exit
|
|
13
|
+
from synth_ai.demos import core as demo_core
|
|
14
|
+
from synth_ai.utils.cli import print_next_step
|
|
15
|
+
from synth_ai.utils.env import mask_str
|
|
16
|
+
from synth_ai.utils.modal import is_modal_public_url
|
|
17
|
+
from synth_ai.utils.process import popen_capture
|
|
18
|
+
from synth_ai.utils.user_config import USER_CONFIG_PATH, update_user_config
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class HandshakeError(Exception):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _get_canonical_origin() -> str:
|
|
26
|
+
"""Resolve the dashboard origin for the browser handshake.
|
|
27
|
+
|
|
28
|
+
Priority order:
|
|
29
|
+
1. Explicit ``SYNTH_CANONICAL_ORIGIN`` override.
|
|
30
|
+
2. Development flag ``SYNTH_CANONICAL_DEV`` (case-insensitive truthy) → localhost.
|
|
31
|
+
3. Production dashboard at ``https://www.usesynth.ai/dashboard``.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
override = (os.getenv("SYNTH_CANONICAL_ORIGIN") or "").strip()
|
|
35
|
+
if override:
|
|
36
|
+
return override.rstrip("/")
|
|
37
|
+
|
|
38
|
+
dev_flag = (os.getenv("SYNTH_CANONICAL_DEV") or "").strip().lower()
|
|
39
|
+
if dev_flag in { "1", "true", "yes", "on" }:
|
|
40
|
+
print("USING DEV ORIGIN")
|
|
41
|
+
return "http://localhost:3000"
|
|
42
|
+
|
|
43
|
+
return "https://www.usesynth.ai/dashboard"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _split_origin(origin: str) -> tuple[str, str]:
|
|
47
|
+
parsed = urlsplit(origin)
|
|
48
|
+
bare = cast(str, urlunsplit((parsed.scheme, parsed.netloc, "", "", "")))
|
|
49
|
+
path = parsed.path.rstrip("/")
|
|
50
|
+
return bare, path
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _ensure_verification_uri(data: dict[str, Any], base_with_path: str) -> None:
|
|
54
|
+
uri = data.get("verification_uri")
|
|
55
|
+
if not isinstance(uri, str) or not uri:
|
|
56
|
+
return
|
|
57
|
+
if uri.startswith("http://") or uri.startswith("https://"):
|
|
58
|
+
return
|
|
59
|
+
data["verification_uri"] = urljoin(base_with_path.rstrip("/") + "/", uri.lstrip("/"))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _start_handshake_session(origin: str | None = None) -> tuple[str, str, int, int]:
|
|
63
|
+
base = (origin or _get_canonical_origin()).rstrip("/")
|
|
64
|
+
api_origin, _ = _split_origin(base)
|
|
65
|
+
url = urljoin(api_origin.rstrip("/") + "/", "api/sdk/handshake/init")
|
|
66
|
+
r = requests.post(url, timeout=10)
|
|
67
|
+
if r.status_code != 200:
|
|
68
|
+
raise HandshakeError(f"init failed: {r.status_code} {r.text}")
|
|
69
|
+
try:
|
|
70
|
+
data = r.json()
|
|
71
|
+
except ValueError as exc: # pragma: no cover - network dependent
|
|
72
|
+
raise HandshakeError(f"init returned malformed JSON: {exc}") from exc
|
|
73
|
+
_ensure_verification_uri(data, base)
|
|
74
|
+
return (
|
|
75
|
+
str(data.get("device_code")),
|
|
76
|
+
str(data.get("verification_uri")),
|
|
77
|
+
int(data.get("expires_in", 600)),
|
|
78
|
+
int(data.get("interval", 3)),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _poll_handshake_token(
|
|
83
|
+
device_code: str, origin: str | None = None, *, timeout_s: int | None = None
|
|
84
|
+
) -> dict[str, Any]:
|
|
85
|
+
base = (origin or _get_canonical_origin()).rstrip("/")
|
|
86
|
+
api_origin, _ = _split_origin(base)
|
|
87
|
+
url = urljoin(api_origin.rstrip("/") + "/", "api/sdk/handshake/token")
|
|
88
|
+
deadline = time.time() + (timeout_s or 600)
|
|
89
|
+
while True:
|
|
90
|
+
if time.time() > deadline:
|
|
91
|
+
raise HandshakeError("handshake timed out")
|
|
92
|
+
try:
|
|
93
|
+
r = requests.post(url, json={"device_code": device_code}, timeout=10)
|
|
94
|
+
except Exception:
|
|
95
|
+
time.sleep(2)
|
|
96
|
+
continue
|
|
97
|
+
if r.status_code == 200:
|
|
98
|
+
try:
|
|
99
|
+
data = r.json()
|
|
100
|
+
except ValueError as exc: # pragma: no cover - network dependent
|
|
101
|
+
raise HandshakeError(f"token returned malformed JSON: {exc}") from exc
|
|
102
|
+
_ensure_verification_uri(data, base)
|
|
103
|
+
return data
|
|
104
|
+
elif r.status_code in (404, 410):
|
|
105
|
+
raise HandshakeError(f"handshake failed: {r.status_code}")
|
|
106
|
+
# 428 authorization_pending or others → wait and retry
|
|
107
|
+
time.sleep(2)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _run_handshake(origin: str | None = None) -> dict[str, Any]:
|
|
111
|
+
device_code, verification_uri, expires_in, interval = _start_handshake_session(origin)
|
|
112
|
+
with contextlib.suppress(Exception):
|
|
113
|
+
webbrowser.open(verification_uri)
|
|
114
|
+
return _poll_handshake_token(device_code, origin, timeout_s=expires_in)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def setup() -> int:
|
|
119
|
+
# Prefer the demo directory provided in the current shell session, then fall back to persisted state
|
|
120
|
+
demo_dir_env = (os.environ.get("DEMO_DIR") or "").strip()
|
|
121
|
+
demo_dir: str | None = None
|
|
122
|
+
if demo_dir_env:
|
|
123
|
+
candidate = Path(demo_dir_env).expanduser()
|
|
124
|
+
if candidate.is_dir():
|
|
125
|
+
demo_dir = str(candidate.resolve())
|
|
126
|
+
else:
|
|
127
|
+
print(f"Warning: DEMO_DIR={demo_dir_env} does not exist; falling back to stored demo directory.")
|
|
128
|
+
|
|
129
|
+
if demo_dir is None:
|
|
130
|
+
loaded = demo_core.load_demo_dir()
|
|
131
|
+
if loaded:
|
|
132
|
+
demo_dir = loaded
|
|
133
|
+
|
|
134
|
+
if demo_dir and os.path.isdir(demo_dir):
|
|
135
|
+
os.chdir(demo_dir)
|
|
136
|
+
print(f"Using demo directory: {demo_dir}")
|
|
137
|
+
|
|
138
|
+
synth_key = ""
|
|
139
|
+
rl_env_key = ""
|
|
140
|
+
org_name = ""
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
print("\n⏳ Connecting to your browser session…")
|
|
144
|
+
res = _run_handshake()
|
|
145
|
+
org = res.get("org") or {}
|
|
146
|
+
keys = res.get("keys") or {}
|
|
147
|
+
synth_key = str(keys.get("synth") or "").strip()
|
|
148
|
+
rl_env_key = str(keys.get("rl_env") or "").strip()
|
|
149
|
+
org_name = org.get("name") or "Unamed Organization ™️"
|
|
150
|
+
print(f"✅ Connected to {org_name}!")
|
|
151
|
+
except (HandshakeError, Exception) as exc:
|
|
152
|
+
print(f"⚠️ Failed to fetch keys from frontend: {exc}")
|
|
153
|
+
print("Falling back to manual entry...")
|
|
154
|
+
|
|
155
|
+
if not synth_key:
|
|
156
|
+
try:
|
|
157
|
+
synth_key = input(
|
|
158
|
+
"Failed to fetch your Synth API key. Please enter your Synth API key here:\n> "
|
|
159
|
+
).strip()
|
|
160
|
+
except (EOFError, KeyboardInterrupt):
|
|
161
|
+
print("\nSetup cancelled.")
|
|
162
|
+
return 1
|
|
163
|
+
if not synth_key:
|
|
164
|
+
print("Synth API key is required.")
|
|
165
|
+
return 1
|
|
166
|
+
|
|
167
|
+
if not rl_env_key:
|
|
168
|
+
try:
|
|
169
|
+
rl_env_key = input(
|
|
170
|
+
"Failed to fetch your Environment API key. Please enter your Environment API key here:\n> "
|
|
171
|
+
).strip()
|
|
172
|
+
except (EOFError, KeyboardInterrupt):
|
|
173
|
+
print("\nSetup cancelled.")
|
|
174
|
+
return 1
|
|
175
|
+
if not rl_env_key:
|
|
176
|
+
print("Environment API key is required.")
|
|
177
|
+
return 1
|
|
178
|
+
|
|
179
|
+
# Persist keys to user config
|
|
180
|
+
config_updates = {
|
|
181
|
+
"SYNTH_API_KEY": synth_key,
|
|
182
|
+
"ENVIRONMENT_API_KEY": rl_env_key,
|
|
183
|
+
}
|
|
184
|
+
update_user_config(config_updates)
|
|
185
|
+
|
|
186
|
+
os.environ["SYNTH_API_KEY"] = synth_key
|
|
187
|
+
os.environ["ENVIRONMENT_API_KEY"] = rl_env_key
|
|
188
|
+
|
|
189
|
+
env = demo_core.load_env()
|
|
190
|
+
|
|
191
|
+
def _refresh_env() -> None:
|
|
192
|
+
nonlocal env
|
|
193
|
+
env = demo_core.load_env()
|
|
194
|
+
|
|
195
|
+
def _maybe_fix_task_url() -> None:
|
|
196
|
+
if not env.task_app_name:
|
|
197
|
+
return
|
|
198
|
+
current = env.task_app_base_url
|
|
199
|
+
needs_lookup = not current or not is_modal_public_url(current)
|
|
200
|
+
if not needs_lookup:
|
|
201
|
+
return
|
|
202
|
+
code, out = popen_capture(
|
|
203
|
+
[
|
|
204
|
+
"uv",
|
|
205
|
+
"run",
|
|
206
|
+
"python",
|
|
207
|
+
"-m",
|
|
208
|
+
"modal",
|
|
209
|
+
"app",
|
|
210
|
+
"url",
|
|
211
|
+
env.task_app_name,
|
|
212
|
+
]
|
|
213
|
+
)
|
|
214
|
+
if code != 0 or not out:
|
|
215
|
+
return
|
|
216
|
+
new_url = ""
|
|
217
|
+
for token in out.split():
|
|
218
|
+
if is_modal_public_url(token):
|
|
219
|
+
new_url = token.strip().rstrip("/")
|
|
220
|
+
break
|
|
221
|
+
if new_url and new_url != current:
|
|
222
|
+
print(f"Updating TASK_APP_BASE_URL from Modal CLI → {new_url}")
|
|
223
|
+
persist_path = demo_dir or os.getcwd()
|
|
224
|
+
demo_core.persist_task_url(new_url, name=env.task_app_name, path=persist_path)
|
|
225
|
+
os.environ["TASK_APP_BASE_URL"] = new_url
|
|
226
|
+
_refresh_env()
|
|
227
|
+
|
|
228
|
+
modal_ok, modal_msg = demo_core.modal_auth_status()
|
|
229
|
+
if modal_ok:
|
|
230
|
+
print(f"✓ Modal authenticated: {modal_msg}")
|
|
231
|
+
else:
|
|
232
|
+
print(f"[setup] Modal authentication status: {modal_msg}")
|
|
233
|
+
|
|
234
|
+
_maybe_fix_task_url()
|
|
235
|
+
|
|
236
|
+
if env.dev_backend_url:
|
|
237
|
+
api = env.dev_backend_url.rstrip("/") + (
|
|
238
|
+
"" if env.dev_backend_url.endswith("/api") else "/api"
|
|
239
|
+
)
|
|
240
|
+
demo_core.assert_http_ok(api + "/health", method="GET")
|
|
241
|
+
if env.task_app_base_url:
|
|
242
|
+
base = env.task_app_base_url.rstrip("/")
|
|
243
|
+
demo_core.assert_http_ok(
|
|
244
|
+
base + "/health", method="GET"
|
|
245
|
+
) or demo_core.assert_http_ok(
|
|
246
|
+
base, method="GET"
|
|
247
|
+
)
|
|
248
|
+
print("\nSaved keys:")
|
|
249
|
+
print(f" SYNTH_API_KEY={mask_str(synth_key)}")
|
|
250
|
+
print(f" ENVIRONMENT_API_KEY={mask_str(rl_env_key)}")
|
|
251
|
+
if env.task_app_base_url:
|
|
252
|
+
print(f" TASK_APP_BASE_URL={env.task_app_base_url}")
|
|
253
|
+
print(f"Configuration persisted to: {USER_CONFIG_PATH}")
|
|
254
|
+
|
|
255
|
+
demo_core.persist_demo_dir(os.getcwd())
|
|
256
|
+
|
|
257
|
+
print_next_step("deploy our task app", ["uvx synth-ai deploy"])
|
|
258
|
+
return 0
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def register(group):
|
|
262
|
+
@group.command("setup")
|
|
263
|
+
def demo_setup():
|
|
264
|
+
code = setup()
|
|
265
|
+
if code:
|
|
266
|
+
raise Exit(code)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Compatibility wrapper for task-app deploy command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from .task_apps import task_app_group
|
|
8
|
+
|
|
9
|
+
_deploy = task_app_group.commands.get("deploy")
|
|
10
|
+
|
|
11
|
+
if _deploy is None:
|
|
12
|
+
raise RuntimeError("task_app_group does not define a 'deploy' command")
|
|
13
|
+
|
|
14
|
+
deploy_command: click.Command = _deploy
|
|
15
|
+
|
|
16
|
+
__all__ = ["deploy_command"]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Task app list command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
from synth_ai.task.apps import registry
|
|
7
|
+
|
|
8
|
+
from .task_apps import task_app_group
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@task_app_group.command("list")
|
|
12
|
+
def list_apps() -> None:
|
|
13
|
+
"""List registered task apps."""
|
|
14
|
+
|
|
15
|
+
entries = registry.list()
|
|
16
|
+
if not entries:
|
|
17
|
+
click.echo("No task apps registered.")
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
for entry in entries:
|
|
21
|
+
aliases = f" (aliases: {', '.join(entry.aliases)})" if entry.aliases else ""
|
|
22
|
+
click.echo(f"- {entry.app_id}{aliases}: {entry.description}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
__all__ = ["list_apps"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Compatibility wrapper for task-app modal-serve command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from .task_apps import task_app_group
|
|
8
|
+
|
|
9
|
+
_modal_serve = task_app_group.commands.get("modal-serve")
|
|
10
|
+
|
|
11
|
+
if _modal_serve is None:
|
|
12
|
+
raise RuntimeError("task_app_group does not define a 'modal-serve' command")
|
|
13
|
+
|
|
14
|
+
modal_serve_command: click.Command = _modal_serve
|
|
15
|
+
|
|
16
|
+
__all__ = ["modal_serve_command"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Compatibility wrapper for task-app serve command."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from .task_apps import serve_command as task_app_serve_command
|
|
8
|
+
from .task_apps import task_app_group
|
|
9
|
+
|
|
10
|
+
serve_command = task_app_serve_command
|
|
11
|
+
|
|
12
|
+
_group_serve = task_app_group.commands.get("serve")
|
|
13
|
+
if _group_serve is None:
|
|
14
|
+
raise RuntimeError("task_app_group does not define a 'serve' command")
|
|
15
|
+
|
|
16
|
+
serve_task_group: click.Command = _group_serve
|
|
17
|
+
|
|
18
|
+
__all__ = ["serve_command", "serve_task_group"]
|