happyhorse-cli 2026.10.19.4__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.
- happyhorse_cli-2026.10.19.4/.env.example +4 -0
- happyhorse_cli-2026.10.19.4/.gitignore +32 -0
- happyhorse_cli-2026.10.19.4/CHANGELOG.md +19 -0
- happyhorse_cli-2026.10.19.4/LICENSE +21 -0
- happyhorse_cli-2026.10.19.4/PKG-INFO +138 -0
- happyhorse_cli-2026.10.19.4/README.md +92 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/__init__.py +1 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/__main__.py +5 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/commands/__init__.py +0 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/commands/info.py +30 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/commands/task.py +160 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/commands/video.py +408 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/core/__init__.py +0 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/core/client.py +107 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/core/config.py +39 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/core/exceptions.py +37 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/core/output.py +138 -0
- happyhorse_cli-2026.10.19.4/happyhorse_cli/main.py +73 -0
- happyhorse_cli-2026.10.19.4/pyproject.toml +118 -0
- happyhorse_cli-2026.10.19.4/tests/__init__.py +0 -0
- happyhorse_cli-2026.10.19.4/tests/conftest.py +101 -0
- happyhorse_cli-2026.10.19.4/tests/test_client.py +74 -0
- happyhorse_cli-2026.10.19.4/tests/test_commands.py +307 -0
- happyhorse_cli-2026.10.19.4/tests/test_config.py +39 -0
- happyhorse_cli-2026.10.19.4/tests/test_integration.py +35 -0
- happyhorse_cli-2026.10.19.4/tests/test_output.py +93 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
*.egg
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
ENV/
|
|
16
|
+
|
|
17
|
+
# Environment variables
|
|
18
|
+
.env
|
|
19
|
+
|
|
20
|
+
# IDE
|
|
21
|
+
.vscode/
|
|
22
|
+
.idea/
|
|
23
|
+
*.swp
|
|
24
|
+
*.swo
|
|
25
|
+
|
|
26
|
+
# Testing
|
|
27
|
+
.coverage
|
|
28
|
+
htmlcov/
|
|
29
|
+
.pytest_cache/
|
|
30
|
+
|
|
31
|
+
# mypy
|
|
32
|
+
.mypy_cache/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Calendar Versioning](https://calver.org/) (YYYY.MM.DD.BUILD).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-07-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release
|
|
12
|
+
- HappyHorse video generation from text prompts (generate)
|
|
13
|
+
- Image-to-video generation (image-to-video)
|
|
14
|
+
- Reference-to-video generation (reference-to-video)
|
|
15
|
+
- Video editing (video-edit)
|
|
16
|
+
- Task management with polling
|
|
17
|
+
- Rich terminal output with tables and panels
|
|
18
|
+
- JSON output mode (`--json` flag)
|
|
19
|
+
- Multiple model support
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AceDataCloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: happyhorse-cli
|
|
3
|
+
Version: 2026.10.19.4
|
|
4
|
+
Summary: CLI tool for HappyHorse AI Video Generation via AceDataCloud API
|
|
5
|
+
Project-URL: Homepage, https://github.com/AceDataCloud/HappyHorseCli
|
|
6
|
+
Project-URL: Repository, https://github.com/AceDataCloud/HappyHorseCli
|
|
7
|
+
Project-URL: Issues, https://github.com/AceDataCloud/HappyHorseCli/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/AceDataCloud/HappyHorseCli/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: AceDataCloud <support@acedata.cloud>
|
|
10
|
+
Maintainer-email: AceDataCloud <support@acedata.cloud>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: acedata,ai,cli,command-line,generation,happyhorse,video
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Multimedia :: Video
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: click>=8.1.0
|
|
27
|
+
Requires-Dist: httpx>=0.27.0
|
|
28
|
+
Requires-Dist: pydantic>=2.0.0
|
|
29
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
30
|
+
Requires-Dist: rich>=13.0.0
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: happyhorse-cli[dev,release,test]; extra == 'all'
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: mypy>=1.10.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pre-commit>=3.7.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
37
|
+
Provides-Extra: release
|
|
38
|
+
Requires-Dist: build>=1.2.0; extra == 'release'
|
|
39
|
+
Requires-Dist: twine>=6.1.0; extra == 'release'
|
|
40
|
+
Provides-Extra: test
|
|
41
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'test'
|
|
42
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'test'
|
|
43
|
+
Requires-Dist: pytest>=8.0.0; extra == 'test'
|
|
44
|
+
Requires-Dist: respx>=0.21.0; extra == 'test'
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
|
|
47
|
+
# HappyHorse by Ace Data Cloud — source CLI
|
|
48
|
+
|
|
49
|
+
A command-line tool for AI video generation using HappyHorse through the AceDataCloud platform.
|
|
50
|
+
|
|
51
|
+
## Installation status
|
|
52
|
+
|
|
53
|
+
The HappyHorse MCP package is publicly available at [mcp-happyhorse](https://pypi.org/project/mcp-happyhorse/) from [AceDataCloud/HappyHorseMCP](https://github.com/AceDataCloud/HappyHorseMCP). This CLI is maintained in the Clis source repository; the [HappyHorseCli mirror](https://github.com/AceDataCloud/HappyHorseCli) now contains this source and its standard build workflow. A PyPI release named `happyhorse-cli` is **not published as of 2026-10-19**. The existing publisher's new-project allowance resumes on 2026-10-20; until the first exact-version receipt, this remains a source installation. Use the existing published MCP if you need a registry-distributed integration.
|
|
54
|
+
|
|
55
|
+
For the source CLI, use the pinned source below in an isolated Python environment; it is a local source installation, not a PyPI release. [中文安装与密钥指南](https://github.com/AceDataCloud/Clis/blob/main/docs/SERVICE_PACKAGES_zh-CN.md)
|
|
56
|
+
|
|
57
|
+
The [publication checklist](https://github.com/AceDataCloud/Clis/blob/main/happyhorse/PUBLICATION.md) records the concrete mirror/package release steps and the temporary publisher-project allowance gate. The repository is already populated; no new account registration is required.
|
|
58
|
+
|
|
59
|
+
## Source installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python -m pip install "git+https://github.com/AceDataCloud/Clis.git@06c580dbfddd59f9b9bb1c80e86776723fc6cfd3#subdirectory=happyhorse"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API key and free local checks
|
|
66
|
+
|
|
67
|
+
Register/sign in at [Applications](https://platform.acedata.cloud/console/applications?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen&utm_content=happyhorse_cli_readme_api_key), initialize General application if needed, and copy or create an API Key with HappyHorse generation and task-query access. Check expiration, limits, balance and [current pricing](https://platform.acedata.cloud/models?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen&utm_content=happyhorse_cli_readme_pricing). Store only the raw token in `ACEDATACLOUD_API_TOKEN`, never a prompt or commit. A platform account-management token is different.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
happyhorse --help
|
|
71
|
+
happyhorse models
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
These are local reference commands. Generation is charged under your current account terms. Save its task ID; use `happyhorse task <task-id>` or `happyhorse wait <task-id>` for that same task instead of generating again.
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Set API token
|
|
80
|
+
export ACEDATACLOUD_API_TOKEN=your_token_here
|
|
81
|
+
|
|
82
|
+
# Generate video from text
|
|
83
|
+
happyhorse generate "A horse galloping through a field"
|
|
84
|
+
|
|
85
|
+
# Generate video from image
|
|
86
|
+
happyhorse image-to-video "Animate this scene" --image-url https://example.com/photo.jpg
|
|
87
|
+
|
|
88
|
+
# Generate video from reference images
|
|
89
|
+
happyhorse reference-to-video "Create scene" --image-urls https://example.com/ref.jpg
|
|
90
|
+
|
|
91
|
+
# Edit a video
|
|
92
|
+
happyhorse video-edit "Add dramatic music" --video-url https://example.com/video.mp4
|
|
93
|
+
|
|
94
|
+
# Check task status
|
|
95
|
+
happyhorse task abc123-def456
|
|
96
|
+
|
|
97
|
+
# Wait for task completion
|
|
98
|
+
happyhorse wait abc123 --interval 5
|
|
99
|
+
|
|
100
|
+
# List available models
|
|
101
|
+
happyhorse models
|
|
102
|
+
|
|
103
|
+
# Show configuration
|
|
104
|
+
happyhorse config
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Options
|
|
108
|
+
|
|
109
|
+
### generate
|
|
110
|
+
|
|
111
|
+
| Option | Default | Description |
|
|
112
|
+
|--------|---------|-------------|
|
|
113
|
+
| `--model` | `happyhorse-1.1-t2v` | Model to use |
|
|
114
|
+
| `--resolution` | `1080P` | Video resolution (720P, 1080P) |
|
|
115
|
+
| `--ratio` | `16:9` | Aspect ratio (16:9, 9:16, 1:1, 4:3, 3:4) |
|
|
116
|
+
| `--duration` | `5` | Duration in seconds |
|
|
117
|
+
| `--watermark` | `False` | Add watermark |
|
|
118
|
+
| `--audio-setting` | `auto` | Audio setting (auto, origin) |
|
|
119
|
+
| `--seed` | None | Random seed |
|
|
120
|
+
| `--callback-url` | None | Webhook callback URL |
|
|
121
|
+
| `--async` | `False` | Submit asynchronously |
|
|
122
|
+
| `--json` | `False` | Output raw JSON |
|
|
123
|
+
|
|
124
|
+
## Models
|
|
125
|
+
|
|
126
|
+
| Model | Type |
|
|
127
|
+
|-------|------|
|
|
128
|
+
| `happyhorse-1.0-t2v` | Text-to-Video |
|
|
129
|
+
| `happyhorse-1.1-t2v` | Text-to-Video (default) |
|
|
130
|
+
| `happyhorse-1.0-i2v` | Image-to-Video |
|
|
131
|
+
| `happyhorse-1.1-i2v` | Image-to-Video |
|
|
132
|
+
| `happyhorse-1.0-r2v` | Reference-to-Video |
|
|
133
|
+
| `happyhorse-1.1-r2v` | Reference-to-Video |
|
|
134
|
+
| `happyhorse-1.0-video-edit` | Video Edit |
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# HappyHorse by Ace Data Cloud — source CLI
|
|
2
|
+
|
|
3
|
+
A command-line tool for AI video generation using HappyHorse through the AceDataCloud platform.
|
|
4
|
+
|
|
5
|
+
## Installation status
|
|
6
|
+
|
|
7
|
+
The HappyHorse MCP package is publicly available at [mcp-happyhorse](https://pypi.org/project/mcp-happyhorse/) from [AceDataCloud/HappyHorseMCP](https://github.com/AceDataCloud/HappyHorseMCP). This CLI is maintained in the Clis source repository; the [HappyHorseCli mirror](https://github.com/AceDataCloud/HappyHorseCli) now contains this source and its standard build workflow. A PyPI release named `happyhorse-cli` is **not published as of 2026-10-19**. The existing publisher's new-project allowance resumes on 2026-10-20; until the first exact-version receipt, this remains a source installation. Use the existing published MCP if you need a registry-distributed integration.
|
|
8
|
+
|
|
9
|
+
For the source CLI, use the pinned source below in an isolated Python environment; it is a local source installation, not a PyPI release. [中文安装与密钥指南](https://github.com/AceDataCloud/Clis/blob/main/docs/SERVICE_PACKAGES_zh-CN.md)
|
|
10
|
+
|
|
11
|
+
The [publication checklist](https://github.com/AceDataCloud/Clis/blob/main/happyhorse/PUBLICATION.md) records the concrete mirror/package release steps and the temporary publisher-project allowance gate. The repository is already populated; no new account registration is required.
|
|
12
|
+
|
|
13
|
+
## Source installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
python -m pip install "git+https://github.com/AceDataCloud/Clis.git@06c580dbfddd59f9b9bb1c80e86776723fc6cfd3#subdirectory=happyhorse"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## API key and free local checks
|
|
20
|
+
|
|
21
|
+
Register/sign in at [Applications](https://platform.acedata.cloud/console/applications?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen&utm_content=happyhorse_cli_readme_api_key), initialize General application if needed, and copy or create an API Key with HappyHorse generation and task-query access. Check expiration, limits, balance and [current pricing](https://platform.acedata.cloud/models?utm_source=opensource&utm_medium=referral&utm_campaign=evergreen&utm_content=happyhorse_cli_readme_pricing). Store only the raw token in `ACEDATACLOUD_API_TOKEN`, never a prompt or commit. A platform account-management token is different.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
happyhorse --help
|
|
25
|
+
happyhorse models
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
These are local reference commands. Generation is charged under your current account terms. Save its task ID; use `happyhorse task <task-id>` or `happyhorse wait <task-id>` for that same task instead of generating again.
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Set API token
|
|
34
|
+
export ACEDATACLOUD_API_TOKEN=your_token_here
|
|
35
|
+
|
|
36
|
+
# Generate video from text
|
|
37
|
+
happyhorse generate "A horse galloping through a field"
|
|
38
|
+
|
|
39
|
+
# Generate video from image
|
|
40
|
+
happyhorse image-to-video "Animate this scene" --image-url https://example.com/photo.jpg
|
|
41
|
+
|
|
42
|
+
# Generate video from reference images
|
|
43
|
+
happyhorse reference-to-video "Create scene" --image-urls https://example.com/ref.jpg
|
|
44
|
+
|
|
45
|
+
# Edit a video
|
|
46
|
+
happyhorse video-edit "Add dramatic music" --video-url https://example.com/video.mp4
|
|
47
|
+
|
|
48
|
+
# Check task status
|
|
49
|
+
happyhorse task abc123-def456
|
|
50
|
+
|
|
51
|
+
# Wait for task completion
|
|
52
|
+
happyhorse wait abc123 --interval 5
|
|
53
|
+
|
|
54
|
+
# List available models
|
|
55
|
+
happyhorse models
|
|
56
|
+
|
|
57
|
+
# Show configuration
|
|
58
|
+
happyhorse config
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Options
|
|
62
|
+
|
|
63
|
+
### generate
|
|
64
|
+
|
|
65
|
+
| Option | Default | Description |
|
|
66
|
+
|--------|---------|-------------|
|
|
67
|
+
| `--model` | `happyhorse-1.1-t2v` | Model to use |
|
|
68
|
+
| `--resolution` | `1080P` | Video resolution (720P, 1080P) |
|
|
69
|
+
| `--ratio` | `16:9` | Aspect ratio (16:9, 9:16, 1:1, 4:3, 3:4) |
|
|
70
|
+
| `--duration` | `5` | Duration in seconds |
|
|
71
|
+
| `--watermark` | `False` | Add watermark |
|
|
72
|
+
| `--audio-setting` | `auto` | Audio setting (auto, origin) |
|
|
73
|
+
| `--seed` | None | Random seed |
|
|
74
|
+
| `--callback-url` | None | Webhook callback URL |
|
|
75
|
+
| `--async` | `False` | Submit asynchronously |
|
|
76
|
+
| `--json` | `False` | Output raw JSON |
|
|
77
|
+
|
|
78
|
+
## Models
|
|
79
|
+
|
|
80
|
+
| Model | Type |
|
|
81
|
+
|-------|------|
|
|
82
|
+
| `happyhorse-1.0-t2v` | Text-to-Video |
|
|
83
|
+
| `happyhorse-1.1-t2v` | Text-to-Video (default) |
|
|
84
|
+
| `happyhorse-1.0-i2v` | Image-to-Video |
|
|
85
|
+
| `happyhorse-1.1-i2v` | Image-to-Video |
|
|
86
|
+
| `happyhorse-1.0-r2v` | Reference-to-Video |
|
|
87
|
+
| `happyhorse-1.1-r2v` | Reference-to-Video |
|
|
88
|
+
| `happyhorse-1.0-video-edit` | Video Edit |
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""HappyHorse CLI - AI Video Generation via AceDataCloud API."""
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Info and utility commands."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
from happyhorse_cli.core.config import settings
|
|
6
|
+
from happyhorse_cli.core.output import console, print_models
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@click.command()
|
|
10
|
+
def models() -> None:
|
|
11
|
+
"""List available HappyHorse models."""
|
|
12
|
+
print_models()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@click.command()
|
|
16
|
+
def config() -> None:
|
|
17
|
+
"""Show current configuration."""
|
|
18
|
+
from rich.table import Table
|
|
19
|
+
|
|
20
|
+
table = Table(title="HappyHorse CLI Configuration")
|
|
21
|
+
table.add_column("Setting", style="bold cyan")
|
|
22
|
+
table.add_column("Value")
|
|
23
|
+
|
|
24
|
+
table.add_row("API Base URL", settings.api_base_url)
|
|
25
|
+
table.add_row(
|
|
26
|
+
"API Token", f"{settings.api_token[:8]}..." if settings.api_token else "[red]Not set[/red]"
|
|
27
|
+
)
|
|
28
|
+
table.add_row("Request Timeout", f"{settings.request_timeout}s")
|
|
29
|
+
|
|
30
|
+
console.print(table)
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""Task management commands."""
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from happyhorse_cli.core.client import get_client
|
|
8
|
+
from happyhorse_cli.core.exceptions import HappyHorseError
|
|
9
|
+
from happyhorse_cli.core.output import (
|
|
10
|
+
print_error,
|
|
11
|
+
print_json,
|
|
12
|
+
print_success,
|
|
13
|
+
print_task_result,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.command()
|
|
18
|
+
@click.argument("task_id")
|
|
19
|
+
@click.option("--json", "output_json", is_flag=True, help="Output raw JSON.")
|
|
20
|
+
@click.pass_context
|
|
21
|
+
def task(
|
|
22
|
+
ctx: click.Context,
|
|
23
|
+
task_id: str,
|
|
24
|
+
output_json: bool,
|
|
25
|
+
) -> None:
|
|
26
|
+
"""Query a single task status.
|
|
27
|
+
|
|
28
|
+
TASK_ID is the task ID returned from generate commands.
|
|
29
|
+
|
|
30
|
+
\b
|
|
31
|
+
Examples:
|
|
32
|
+
happyhorse task abc123-def456
|
|
33
|
+
"""
|
|
34
|
+
client = get_client(ctx.obj.get("token"))
|
|
35
|
+
try:
|
|
36
|
+
result = client.query_task(id=task_id, action="retrieve")
|
|
37
|
+
if output_json:
|
|
38
|
+
print_json(result)
|
|
39
|
+
else:
|
|
40
|
+
print_task_result(result)
|
|
41
|
+
except HappyHorseError as e:
|
|
42
|
+
print_error(e.message)
|
|
43
|
+
raise SystemExit(1) from e
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@click.command("tasks")
|
|
47
|
+
@click.argument("task_ids", nargs=-1, required=True)
|
|
48
|
+
@click.option("--json", "output_json", is_flag=True, help="Output raw JSON.")
|
|
49
|
+
@click.pass_context
|
|
50
|
+
def tasks_batch(
|
|
51
|
+
ctx: click.Context,
|
|
52
|
+
task_ids: tuple[str, ...],
|
|
53
|
+
output_json: bool,
|
|
54
|
+
) -> None:
|
|
55
|
+
"""Query multiple tasks at once.
|
|
56
|
+
|
|
57
|
+
TASK_IDS are space-separated task IDs.
|
|
58
|
+
|
|
59
|
+
\b
|
|
60
|
+
Examples:
|
|
61
|
+
happyhorse tasks abc123 def456 ghi789
|
|
62
|
+
"""
|
|
63
|
+
client = get_client(ctx.obj.get("token"))
|
|
64
|
+
try:
|
|
65
|
+
result = client.query_task(ids=list(task_ids), action="retrieve_batch")
|
|
66
|
+
if output_json:
|
|
67
|
+
print_json(result)
|
|
68
|
+
else:
|
|
69
|
+
print_task_result(result)
|
|
70
|
+
except HappyHorseError as e:
|
|
71
|
+
print_error(e.message)
|
|
72
|
+
raise SystemExit(1) from e
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@click.command()
|
|
76
|
+
@click.argument("task_id")
|
|
77
|
+
@click.option(
|
|
78
|
+
"--interval",
|
|
79
|
+
type=int,
|
|
80
|
+
default=5,
|
|
81
|
+
help="Polling interval in seconds (default: 5).",
|
|
82
|
+
)
|
|
83
|
+
@click.option(
|
|
84
|
+
"--timeout",
|
|
85
|
+
"max_timeout",
|
|
86
|
+
type=int,
|
|
87
|
+
default=600,
|
|
88
|
+
help="Maximum wait time in seconds (default: 600).",
|
|
89
|
+
)
|
|
90
|
+
@click.option("--json", "output_json", is_flag=True, help="Output raw JSON.")
|
|
91
|
+
@click.pass_context
|
|
92
|
+
def wait(
|
|
93
|
+
ctx: click.Context,
|
|
94
|
+
task_id: str,
|
|
95
|
+
interval: int,
|
|
96
|
+
max_timeout: int,
|
|
97
|
+
output_json: bool,
|
|
98
|
+
) -> None:
|
|
99
|
+
"""Wait for a task to complete, polling periodically.
|
|
100
|
+
|
|
101
|
+
TASK_ID is the task ID to monitor.
|
|
102
|
+
|
|
103
|
+
\b
|
|
104
|
+
Examples:
|
|
105
|
+
happyhorse wait abc123
|
|
106
|
+
happyhorse wait abc123 --interval 10 --timeout 300
|
|
107
|
+
"""
|
|
108
|
+
client = get_client(ctx.obj.get("token"))
|
|
109
|
+
elapsed = 0
|
|
110
|
+
|
|
111
|
+
try:
|
|
112
|
+
while elapsed < max_timeout:
|
|
113
|
+
result = client.query_task(id=task_id, action="retrieve")
|
|
114
|
+
|
|
115
|
+
# Check for completion signals
|
|
116
|
+
data = result.get("data", result)
|
|
117
|
+
if isinstance(data, dict):
|
|
118
|
+
item = data
|
|
119
|
+
elif isinstance(data, list) and data:
|
|
120
|
+
item = data[0]
|
|
121
|
+
else:
|
|
122
|
+
item = result
|
|
123
|
+
|
|
124
|
+
state = item.get("state", item.get("status", ""))
|
|
125
|
+
video_url = item.get("video_url") or result.get("video_url")
|
|
126
|
+
error = item.get("error") or result.get("error")
|
|
127
|
+
|
|
128
|
+
if error:
|
|
129
|
+
if output_json:
|
|
130
|
+
print_json(result)
|
|
131
|
+
else:
|
|
132
|
+
print_error(f"Task {task_id} failed: {error}")
|
|
133
|
+
raise SystemExit(1)
|
|
134
|
+
|
|
135
|
+
if state in ("succeeded", "completed", "complete") or video_url:
|
|
136
|
+
if output_json:
|
|
137
|
+
print_json(result)
|
|
138
|
+
else:
|
|
139
|
+
print_success(f"Task {task_id} completed!")
|
|
140
|
+
print_task_result(result)
|
|
141
|
+
return
|
|
142
|
+
|
|
143
|
+
if state in ("failed", "error"):
|
|
144
|
+
if output_json:
|
|
145
|
+
print_json(result)
|
|
146
|
+
else:
|
|
147
|
+
print_error(f"Task {task_id} failed.")
|
|
148
|
+
raise SystemExit(1)
|
|
149
|
+
|
|
150
|
+
if not output_json:
|
|
151
|
+
click.echo(f"Status: {state or 'pending'} (waited {elapsed}s)...", err=True)
|
|
152
|
+
|
|
153
|
+
time.sleep(interval)
|
|
154
|
+
elapsed += interval
|
|
155
|
+
|
|
156
|
+
print_error(f"Timeout: task {task_id} did not complete within {max_timeout}s")
|
|
157
|
+
raise SystemExit(1)
|
|
158
|
+
except HappyHorseError as e:
|
|
159
|
+
print_error(e.message)
|
|
160
|
+
raise SystemExit(1) from e
|