aisam-sdk 0.1.0__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.
@@ -0,0 +1,104 @@
1
+ # Python and tooling
2
+ .venv/
3
+ __pycache__/
4
+ *.py[cod]
5
+ *.egg-info/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .mypy_cache/
11
+ .pyright/
12
+ .hypothesis/
13
+ .tox/
14
+ .nox/
15
+ .dmypy.json
16
+ .coverage
17
+ .coverage.*
18
+ htmlcov/
19
+ coverage/
20
+ .benchmarks/
21
+ .cache/
22
+
23
+ # Node (SDK, Cloudflare Worker)
24
+ node_modules/
25
+ .wrangler/
26
+ *.tsbuildinfo
27
+
28
+ # Secrets and local config (never commit; .env.example is the template)
29
+ .env
30
+ .env.*
31
+ !.env.example
32
+ secrets/
33
+ *.pem
34
+ *.key
35
+
36
+ # Everything the app generates: runs, caches (TTS, LLM answers), the local database,
37
+ # plans, deliveries, downloaded stock and models
38
+ runs/
39
+ models/
40
+ plans/
41
+ deliveries/
42
+ library/stock/
43
+ captures/
44
+ /film.yaml
45
+ /capture.mp4
46
+ *.db
47
+ *.db-journal
48
+ *.db-wal
49
+ *.db-shm
50
+ *.sqlite3
51
+
52
+ # Model weights and interrupted downloads (chunks / partials) — never commit these
53
+ *.onnx
54
+ *.safetensors
55
+ *.gguf
56
+ *.ggml
57
+ *.pt
58
+ *.pth
59
+ *.part
60
+ *.incomplete
61
+ *.crdownload
62
+ *.download
63
+ .huggingface/
64
+ huggingface/
65
+
66
+ # Browser / Playwright local artifacts
67
+ playwright-report/
68
+ test-results/
69
+ .playwright/
70
+
71
+ # Generated media (keep source assets under render/ and docs/screens/)
72
+ *.mp4
73
+ *.mov
74
+ *.mxf
75
+ *.webm
76
+ *.wav
77
+ *.mp3
78
+ *.m4a
79
+ demo-*.png
80
+ demo-*.jpg
81
+ demo-UPLOAD.md
82
+
83
+ # Local overrides and scratch
84
+ .claude/settings.local.json
85
+ .envrc
86
+ .direnv/
87
+ .python-version
88
+ .ipynb_checkpoints/
89
+ *.orig
90
+ *.rej
91
+ *.prof
92
+
93
+ # Editors and OS
94
+ .idea/
95
+ .vscode/
96
+ .cursor/
97
+ *.swp
98
+ .DS_Store
99
+ Thumbs.db
100
+ *.log
101
+ *.tmp
102
+
103
+ # Agent worktrees (keep .claude/skills/)
104
+ .claude/worktrees/
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 AISAM
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
aisam_sdk-0.1.0/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ AISAM SDK
2
+ Copyright 2026 AISAM
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ Trademarks: "AISAM", the AISAM logo and related marks are trademarks of AISAM. As stated in
7
+ section 6 of the License, it does not grant permission to use them, except as required to
8
+ describe the origin of the software. Do not name a product or service "AISAM" or imply that
9
+ AISAM endorses it without written permission (see TRADEMARKS.md in the AISAM repository).
10
+
11
+ The AISAM service itself (the API, studio, rendering engine and models behind it) is not
12
+ part of this package and is governed by the AISAM Terms of Service.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.5
2
+ Name: aisam-sdk
3
+ Version: 0.1.0
4
+ Summary: AISAM API client: plan, review, approve and render faceless videos from code or AI agents.
5
+ Project-URL: Homepage, https://aisam.app
6
+ Project-URL: Documentation, https://aisam.app/llms.txt
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ License-File: NOTICE
10
+ Keywords: ai-agents,aisam,faceless,mcp,sdk,video
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: httpx>=0.27
16
+ Description-Content-Type: text/markdown
17
+
18
+ # aisam-sdk
19
+
20
+ The official Python client for the AISAM API: plan, review, approve and render faceless
21
+ videos from your code or AI agent.
22
+
23
+ ```python
24
+ from aisam_sdk import Aisam
25
+
26
+ aisam = Aisam("https://aisam.app", api_key="aisam_…") # or AISAM_URL / AISAM_API_KEY
27
+ v = aisam.create_video("A 40-second Short: how long sunlight takes to reach us")
28
+ aisam.wait(v["id"], until={"await_plan_approval"}) # the free storyboard is ready
29
+ aisam.save_storyboard(v["id"], "storyboard.png")
30
+ ```
31
+
32
+ A person approves every storyboard before anything renders or publishes. Full guide:
33
+ https://aisam.app/llms.txt.
34
+
35
+ Licensed under the Apache License 2.0. "AISAM" and the AISAM logo are trademarks; the
36
+ licence does not grant rights to use them (see NOTICE).
37
+
38
+ To write a video scene by scene instead of from a prompt: `plan_starter`, `check_plan`, `create_from_plan`,
39
+ `replace_plan`, `frames` and `save_frame`. See docs/SDK.md, "Write the plan yourself".
@@ -0,0 +1,22 @@
1
+ # aisam-sdk
2
+
3
+ The official Python client for the AISAM API: plan, review, approve and render faceless
4
+ videos from your code or AI agent.
5
+
6
+ ```python
7
+ from aisam_sdk import Aisam
8
+
9
+ aisam = Aisam("https://aisam.app", api_key="aisam_…") # or AISAM_URL / AISAM_API_KEY
10
+ v = aisam.create_video("A 40-second Short: how long sunlight takes to reach us")
11
+ aisam.wait(v["id"], until={"await_plan_approval"}) # the free storyboard is ready
12
+ aisam.save_storyboard(v["id"], "storyboard.png")
13
+ ```
14
+
15
+ A person approves every storyboard before anything renders or publishes. Full guide:
16
+ https://aisam.app/llms.txt.
17
+
18
+ Licensed under the Apache License 2.0. "AISAM" and the AISAM logo are trademarks; the
19
+ licence does not grant rights to use them (see NOTICE).
20
+
21
+ To write a video scene by scene instead of from a prompt: `plan_starter`, `check_plan`, `create_from_plan`,
22
+ `replace_plan`, `frames` and `save_frame`. See docs/SDK.md, "Write the plan yourself".
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "aisam-sdk"
3
+ version = "0.1.0"
4
+ description = "AISAM API client: plan, review, approve and render faceless videos from code or AI agents."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE", "NOTICE"]
8
+ requires-python = ">=3.10"
9
+ dependencies = ["httpx>=0.27"]
10
+ keywords = ["aisam", "video", "faceless", "ai-agents", "mcp", "sdk"]
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3",
13
+ "Operating System :: OS Independent",
14
+ "Typing :: Typed",
15
+ ]
16
+
17
+ [project.urls]
18
+ Homepage = "https://aisam.app"
19
+ Documentation = "https://aisam.app/llms.txt"
20
+
21
+ [build-system]
22
+ requires = ["hatchling>=1.26"]
23
+ build-backend = "hatchling.build"
24
+
25
+ [tool.hatch.build.targets.wheel]
26
+ packages = ["src/aisam_sdk"]
@@ -0,0 +1,212 @@
1
+ """AISAM Python SDK (Apache-2.0): a small, typed client for the REST API.
2
+ (``/openapi.json`` has every field.)
3
+
4
+ from aisam_sdk import Aisam
5
+
6
+ client = Aisam("https://aisam.app", api_key="aisam_…") # or AISAM_URL / AISAM_API_KEY
7
+ video = client.create_video("A 40-second Short: how long sunlight takes to reach us")
8
+ video = client.wait(video["id"], until={"await_plan_approval"})
9
+ client.save_storyboard(video["id"], "storyboard.png") # free, before any credits
10
+ # a person reviews the storyboard, then approves (the API key belongs to that person):
11
+ client.approve_plan(video["id"], height=1080, fps=30)
12
+ client.wait(video["id"], until={"await_publish_approval", "approved_for_publish"})
13
+ client.save_video(video["id"], "video.mp4")
14
+
15
+ Agents: AISAM keeps a human approval before anything renders or publishes. An agent can plan,
16
+ revise and fetch storyboards on its own; approval should come from a person's key or the
17
+ studio. Errors raise :class:`AisamError` with the API's own message.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import os
23
+ import time
24
+ from collections.abc import Iterable
25
+ from pathlib import Path
26
+ from typing import Any
27
+
28
+ import httpx
29
+
30
+ DONE = {"await_publish_approval", "approved_for_publish", "published"}
31
+ FAILED = {"failed", "rejected"}
32
+
33
+
34
+ class AisamError(RuntimeError):
35
+ def __init__(self, status: int, message: str) -> None:
36
+ super().__init__(f"{status}: {message}")
37
+ self.status = status
38
+ self.message = message
39
+
40
+
41
+ class Aisam:
42
+ def __init__(
43
+ self,
44
+ base_url: str | None = None,
45
+ api_key: str | None = None,
46
+ timeout: float = 60.0,
47
+ client: httpx.Client | None = None,
48
+ ) -> None:
49
+ base = (base_url or os.environ.get("AISAM_URL") or "http://127.0.0.1:8000").rstrip("/")
50
+ key = api_key or os.environ.get("AISAM_API_KEY") or ""
51
+ if not key:
52
+ raise ValueError("an API key is required (argument or AISAM_API_KEY)")
53
+ # redirects: finished videos may come from a signed object-storage link (httpx drops
54
+ # the Authorization header when a redirect leaves the API's host)
55
+ self.http = client or httpx.Client(base_url=base, timeout=timeout, follow_redirects=True)
56
+ self.http.headers.update({"Authorization": f"Bearer {key}",
57
+ "User-Agent": "aisam-python-sdk"}) # fmt: skip
58
+
59
+ # ------------------------------------------------------------------ plumbing
60
+ def _call(self, method: str, path: str, **kw: Any) -> Any:
61
+ r = self.http.request(method, path, **kw)
62
+ if r.status_code >= 400:
63
+ try:
64
+ detail = r.json().get("detail", r.text)
65
+ except ValueError:
66
+ detail = r.text
67
+ raise AisamError(r.status_code, str(detail))
68
+ return r.json() if r.headers.get("content-type", "").startswith("application/json") else r
69
+
70
+ def _save(self, path: str, dest: str | Path) -> Path:
71
+ out = Path(dest)
72
+ out.parent.mkdir(parents=True, exist_ok=True)
73
+ with self.http.stream("GET", path, follow_redirects=True) as r:
74
+ if r.status_code >= 400:
75
+ r.read()
76
+ raise AisamError(r.status_code, r.text)
77
+ with out.open("wb") as f:
78
+ for chunk in r.iter_bytes():
79
+ f.write(chunk)
80
+ return out
81
+
82
+ # ------------------------------------------------------------------ account
83
+ def me(self) -> dict[str, Any]:
84
+ """Workspace, role and permissions of this key."""
85
+ return self._call("GET", "/me")
86
+
87
+ def channels(self) -> list[dict[str, Any]]:
88
+ return self._call("GET", "/channels")
89
+
90
+ def library(self) -> dict[str, Any]:
91
+ """Formats, hooks and templates you can ask for."""
92
+ return self._call("GET", "/library")
93
+
94
+ def credits(self) -> dict[str, Any]:
95
+ return self._call("GET", "/billing/status")
96
+
97
+ # ------------------------------------------------------------------ videos
98
+ def create_video(
99
+ self, prompt: str, idempotency_key: str | None = None, **fields: Any
100
+ ) -> dict[str, Any]:
101
+ """Plan a video from one line. Optional fields: format, length_seconds, channel_id,
102
+ audience, tone, hook, cta, music, aspect, height, narrator, presenter, captions,
103
+ quality (review depth) and, for product films, ``launch={...}``. Pass
104
+ ``idempotency_key`` to make retries safe (same key within 24 h = same video)."""
105
+ headers = {"Idempotency-Key": idempotency_key} if idempotency_key else {}
106
+ return self._call("POST", "/videos", json={"prompt": prompt, **fields}, headers=headers)
107
+
108
+ # ------------------------------------------------------------------ plans you write
109
+ def plan_starter(
110
+ self, scenario: str, topic: str = "", aspect: str | None = None
111
+ ) -> dict[str, Any]:
112
+ """A valid plan for a scenario to edit scene by scene. Its ``script.facts`` are the
113
+ only numbers it may show, written as ``{placeholders}``."""
114
+ params = {"scenario": scenario, "topic": topic, **({"aspect": aspect} if aspect else {})}
115
+ return self._call("GET", "/plans/starter", params=params)
116
+
117
+ def check_plan(self, plan: dict[str, Any], channel_id: str | None = None) -> dict[str, Any]:
118
+ """Check a VideoPlan (``render/schema.json``) without storing it: ``{"ok", "errors",
119
+ "problems"}``. ``errors`` stop it being accepted; ``problems`` are the quality gates."""
120
+ return self._call("POST", "/plans/check", json={"plan": plan, "channel_id": channel_id})
121
+
122
+ def create_from_plan(
123
+ self, plan: dict[str, Any], channel_id: str | None = None,
124
+ idempotency_key: str | None = None,
125
+ ) -> dict[str, Any]: # fmt: skip
126
+ """Make a video from a plan you wrote. Scenes are kept as written; numbers are
127
+ recomputed (citations start unverified), the channel's brand applies and files must be
128
+ in the channel library (or ``"gen: <description>"`` for an image). Returns the video
129
+ with ``problems`` from the quality gates."""
130
+ headers = {"Idempotency-Key": idempotency_key} if idempotency_key else {}
131
+ body = {"plan": plan, "channel_id": channel_id}
132
+ return self._call("POST", "/videos", json=body, headers=headers)
133
+
134
+ def replace_plan(self, video_id: str, plan: dict[str, Any]) -> dict[str, Any]:
135
+ """Swap in a whole new plan (same rules as ``create_from_plan``); the old one is kept
136
+ as a version and the storyboard is re-made."""
137
+ return self._call("PUT", f"/videos/{video_id}/plan", json={"plan": plan})
138
+
139
+ def frames(self, video_id: str, times: list[float], height: int = 540) -> dict[str, Any]:
140
+ """Up to six frames of the current plan, drawn now (free): ``{"frames": [{"t",
141
+ "png"}], "lint": [...]}`` with PNGs as base64 and the renderer's frame checks."""
142
+ return self._call(
143
+ "GET", f"/videos/{video_id}/frames", params={"t": times, "height": height}
144
+ )
145
+
146
+ def save_frame(self, video_id: str, t: float, dest: str | Path, height: int = 540) -> Path:
147
+ """One frame of the current plan at ``t`` seconds, saved as a PNG."""
148
+ return self._save(f"/videos/{video_id}/frame?t={t}&height={height}", dest)
149
+
150
+ def files(self, video_id: str, expires_in: int = 3600) -> dict[str, Any]:
151
+ """Expiring signed download links for the finished video and thumbnails (no key
152
+ needed to use them): ``{"video", "thumbnails", "expires_at", "storage"}``."""
153
+ return self._call("GET", f"/videos/{video_id}/files", params={"expires_in": expires_in})
154
+
155
+ def video(self, video_id: str) -> dict[str, Any]:
156
+ """State, plan, review, events and jobs."""
157
+ return self._call("GET", f"/videos/{video_id}")
158
+
159
+ def videos(self, state: str | None = None) -> list[dict[str, Any]]:
160
+ return self._call("GET", "/videos", params={"state": state} if state else None)
161
+
162
+ def request_changes(
163
+ self, video_id: str, note: str = "", hook: str | None = None,
164
+ params: dict[str, Any] | None = None,
165
+ ) -> dict[str, Any]: # fmt: skip
166
+ """Re-plan with a note ("shorter hook", "for beginners"), another hook or new inputs."""
167
+ body = {"note": note, "hook": hook, "params": params}
168
+ return self._call("POST", f"/videos/{video_id}/changes", json=body)
169
+
170
+ def approve_plan(
171
+ self, video_id: str, height: int | None = None, fps: int | None = None,
172
+ export: str | None = None, confirm_facts: bool = False,
173
+ ) -> dict[str, Any]: # fmt: skip
174
+ """Human gate: approve the storyboard and render. Export: height 720/1080/1440/2160
175
+ (capped by the plan), fps 24/25/30/50/60, export draft/standard/high/master."""
176
+ params: dict[str, Any] = {"confirm_facts": str(confirm_facts).lower()}
177
+ params |= {k: v for k, v in (("height", height), ("fps", fps), ("export", export)) if v}
178
+ return self._call("POST", f"/videos/{video_id}/approve-plan", params=params)
179
+
180
+ def approve_publish(self, video_id: str, title_index: int = 0) -> dict[str, Any]:
181
+ return self._call("POST", f"/videos/{video_id}/approve-publish",
182
+ json={"title_index": title_index}) # fmt: skip
183
+
184
+ def reject(self, video_id: str) -> dict[str, Any]:
185
+ return self._call("POST", f"/videos/{video_id}/reject")
186
+
187
+ def package(self, video_id: str) -> dict[str, Any]:
188
+ """Titles, description with chapters and sources, thumbnails, captions."""
189
+ return self._call("GET", f"/videos/{video_id}/package")
190
+
191
+ def save_storyboard(self, video_id: str, dest: str | Path) -> Path:
192
+ return self._save(f"/videos/{video_id}/storyboard", dest)
193
+
194
+ def save_video(self, video_id: str, dest: str | Path) -> Path:
195
+ return self._save(f"/videos/{video_id}/video", dest)
196
+
197
+ def wait(
198
+ self, video_id: str, until: Iterable[str] = DONE, timeout: float = 1800,
199
+ every: float = 3.0,
200
+ ) -> dict[str, Any]: # fmt: skip
201
+ """Poll until the video reaches one of ``until`` (raises on failure or timeout)."""
202
+ goal = set(until)
203
+ deadline = time.monotonic() + timeout
204
+ while True:
205
+ v = self._call("GET", f"/videos/{video_id}")
206
+ if v["state"] in goal:
207
+ return v
208
+ if v["state"] in FAILED:
209
+ raise AisamError(409, f"video {video_id} is {v['state']}: {v.get('error') or ''}")
210
+ if time.monotonic() > deadline:
211
+ raise TimeoutError(f"video {video_id} still {v['state']} after {timeout:.0f}s")
212
+ time.sleep(every)
File without changes