Skip to content

Commit c98cd62

Browse files
author
Weco Dev
committed
Enable run sharing from the client + opt-in for this capability via dashboard
1 parent 7187169 commit c98cd62

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

‎weco/api.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,40 @@ def submit_execution_result(
450450
return None
451451
except Exception:
452452
return None
453+
454+
455+
# --- Share API Functions ---
456+
457+
458+
def create_share_link(
459+
console: Console,
460+
run_id: str,
461+
auth_headers: dict = {},
462+
timeout: Union[int, Tuple[int, int]] = (5, 30),
463+
) -> Optional[str]:
464+
"""Create a public share link for a run.
465+
466+
Args:
467+
console: Rich console for output.
468+
run_id: The run ID to share.
469+
auth_headers: Authentication headers.
470+
timeout: Request timeout.
471+
472+
Returns:
473+
The share ID if successful, or None on failure.
474+
"""
475+
try:
476+
response = requests.post(
477+
f"{__base_url__}/runs/{run_id}/share",
478+
headers=auth_headers,
479+
timeout=timeout,
480+
)
481+
response.raise_for_status()
482+
result = response.json()
483+
return result.get("share_id")
484+
except requests.exceptions.HTTPError as e:
485+
handle_api_error(e, console)
486+
return None
487+
except Exception as e:
488+
console.print(f"[bold red]Error creating share link: {e}[/]")
489+
return None

‎weco/cli.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,23 @@ def _main() -> None:
393393
)
394394
configure_resume_parser(resume_parser)
395395

396+
# --- Share Command Parser Setup ---
397+
share_parser = subparsers.add_parser(
398+
"share",
399+
help="Create a public share link for a run",
400+
formatter_class=argparse.RawTextHelpFormatter,
401+
)
402+
share_parser.add_argument(
403+
"run_id", type=str, help="The UUID of the run to share (e.g., '0002e071-1b67-411f-a514-36947f0c4b31')"
404+
)
405+
share_parser.add_argument(
406+
"--output",
407+
type=str,
408+
choices=["rich", "plain"],
409+
default="rich",
410+
help="Output mode: 'rich' for interactive terminal UI (default), 'plain' for machine-readable text output suitable for LLM agents.",
411+
)
412+
396413
# --- Setup Command Parser Setup ---
397414
setup_parser = subparsers.add_parser("setup", help="Set up Weco for use with AI tools")
398415
configure_setup_parser(setup_parser)
@@ -432,6 +449,11 @@ def _main() -> None:
432449
sys.exit(0)
433450
elif args.command == "resume":
434451
execute_resume_command(args)
452+
elif args.command == "share":
453+
from .share import handle_share_command
454+
455+
handle_share_command(run_id=args.run_id, output_mode=args.output, console=console)
456+
sys.exit(0)
435457
elif args.command == "setup":
436458
from .setup import handle_setup_command
437459

‎weco/share.py‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Share command handler for the Weco CLI."""
2+
3+
import sys
4+
from rich.console import Console
5+
6+
from . import __dashboard_url__
7+
from .api import create_share_link
8+
from .auth import handle_authentication
9+
10+
11+
def handle_share_command(run_id: str, output_mode: str, console: Console) -> None:
12+
"""Handle the `weco share <run_id>` command.
13+
14+
Creates a public share link for the given run. Requires CLI sharing
15+
to be enabled in the user's account settings on the dashboard.
16+
17+
Args:
18+
run_id: UUID of the run to share.
19+
output_mode: 'rich' or 'plain'.
20+
console: Rich console instance for output.
21+
"""
22+
# Authenticate
23+
_, auth_headers = handle_authentication(console)
24+
if not auth_headers:
25+
sys.exit(1)
26+
27+
# Attempt to create the share link
28+
share_id = create_share_link(
29+
console=console,
30+
run_id=run_id,
31+
auth_headers=auth_headers,
32+
)
33+
34+
if share_id is None:
35+
# Error message was already printed by create_share_link / handle_api_error
36+
sys.exit(1)
37+
38+
share_url = f"{__dashboard_url__}/share/{share_id}"
39+
40+
if output_mode == "plain":
41+
console.print(share_url)
42+
else:
43+
console.print()
44+
console.print(f"[bold green]Share link created![/]")
45+
console.print(f"[bold]{share_url}[/]")
46+
console.print()
47+
console.print("[dim]Anyone with this link can view the run's optimization progress and results.[/]")

0 commit comments

Comments
 (0)