@clipen/clipen-cli 1.0.0 → 1.0.2
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.
- package/README.md +56 -48
- package/apps/web/dist/assets/{index-D5D2HiB1.js → index-DPHwA954.js} +1 -1
- package/apps/web/dist/index.html +1 -1
- package/bin/clipen.js +1 -1
- package/package.json +7 -6
- package/pyproject.toml +18 -2
- package/requirements/dev.txt +2 -0
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/__init__.py +7 -7
- package/src/clipen/analysis/artifacts.py +4 -10
- package/src/clipen/analysis/audio.py +10 -8
- package/src/clipen/analysis/evidence_service.py +345 -167
- package/src/clipen/analysis/image_similarity.py +5 -14
- package/src/clipen/analysis/keyframes.py +5 -17
- package/src/clipen/analysis/models.py +5 -7
- package/src/clipen/analysis/qwen_worker.py +19 -54
- package/src/clipen/analysis/resources.py +2 -1
- package/src/clipen/analysis/runtime.py +1 -3
- package/src/clipen/analysis/service.py +16 -48
- package/src/clipen/analysis/setup.py +11 -25
- package/src/clipen/analysis/setup_cli.py +5 -15
- package/src/clipen/analysis/storage.py +96 -278
- package/src/clipen/analysis/transcription.py +40 -82
- package/src/clipen/analysis/visual.py +109 -48
- package/src/clipen/annotations/__init__.py +5 -2
- package/src/clipen/annotations/models.py +1 -1
- package/src/clipen/annotations/storage.py +132 -84
- package/src/clipen/annotations/suggestions.py +3 -8
- package/src/clipen/asr_release.py +4 -11
- package/src/clipen/bootstrap.py +71 -61
- package/src/clipen/{planning/models.py → candidates.py} +29 -47
- package/src/clipen/cli.py +4 -9
- package/src/clipen/controller/app.py +401 -214
- package/src/clipen/controller/server.py +28 -38
- package/src/clipen/domain/__init__.py +1 -1
- package/src/clipen/domain/media_time.py +3 -10
- package/src/clipen/domain/timeline.py +45 -47
- package/src/clipen/domain/validation.py +0 -1
- package/src/clipen/editing/__init__.py +1 -1
- package/src/clipen/editing/agent_models.py +4 -11
- package/src/clipen/editing/agent_repository.py +393 -172
- package/src/clipen/editing/agent_tools.py +180 -99
- package/src/clipen/editing/alignment.py +92 -52
- package/src/clipen/editing/alignment_setup.py +118 -70
- package/src/clipen/editing/alignment_worker.py +11 -9
- package/src/clipen/editing/change_report.py +95 -38
- package/src/clipen/editing/compiler.py +0 -1
- package/src/clipen/editing/component_looks.py +58 -34
- package/src/clipen/editing/component_review.py +34 -38
- package/src/clipen/editing/coordinator.py +213 -92
- package/src/clipen/editing/editorial_review.py +217 -95
- package/src/clipen/editing/evidence_jobs.py +457 -200
- package/src/clipen/editing/history_changes.py +129 -68
- package/src/clipen/editing/music_choices.py +8 -5
- package/src/clipen/editing/production_catalog.py +573 -136
- package/src/clipen/editing/production_limits.py +43 -17
- package/src/clipen/editing/production_media.py +376 -167
- package/src/clipen/editing/production_preview.py +322 -129
- package/src/clipen/editing/production_progress.py +164 -69
- package/src/clipen/editing/production_requirements.py +106 -39
- package/src/clipen/editing/production_tools.py +1064 -462
- package/src/clipen/editing/program_audio.py +211 -81
- package/src/clipen/editing/program_direction.py +59 -25
- package/src/clipen/editing/program_story.py +83 -45
- package/src/clipen/editing/program_subtitles.py +194 -96
- package/src/clipen/editing/programme_review.py +98 -50
- package/src/clipen/editing/prompt_history.py +64 -27
- package/src/clipen/editing/recut.py +65 -25
- package/src/clipen/editing/refinement_references.py +176 -86
- package/src/clipen/editing/resolve_export.py +449 -218
- package/src/clipen/editing/resolve_titles.py +162 -105
- package/src/clipen/editing/skill_tools.py +530 -154
- package/src/clipen/editing/source_dialogue.py +177 -67
- package/src/clipen/editing/speech_coverage.py +42 -22
- package/src/clipen/editing/speech_quality.py +6 -1
- package/src/clipen/editing/tool_receipts.py +78 -32
- package/src/clipen/editing/versions.py +122 -64
- package/src/clipen/editing/visual_preview.py +157 -61
- package/src/clipen/editing/workbench.py +104 -42
- package/src/clipen/finishing/audio.py +69 -30
- package/src/clipen/finishing/catalog.py +176 -93
- package/src/clipen/finishing/models.py +1 -1
- package/src/clipen/finishing/renderer.py +33 -14
- package/src/clipen/mcp_editing/__main__.py +3 -1
- package/src/clipen/mcp_editing/server.py +77 -34
- package/src/clipen/media/__init__.py +3 -3
- package/src/clipen/media/discovery.py +7 -20
- package/src/clipen/media/models.py +7 -18
- package/src/clipen/media/preview.py +14 -24
- package/src/clipen/media/probe.py +16 -44
- package/src/clipen/media/service.py +6 -19
- package/src/clipen/media/storage.py +33 -81
- package/src/clipen/music_vocabulary.py +33 -4
- package/src/clipen/power.py +8 -3
- package/src/clipen/projects/__init__.py +1 -1
- package/src/clipen/projects/deletion.py +19 -32
- package/src/clipen/projects/finishing_schema.py +3 -1
- package/src/clipen/projects/models.py +2 -5
- package/src/clipen/projects/picker.py +13 -37
- package/src/clipen/projects/service.py +8 -24
- package/src/clipen/projects/storage.py +226 -246
- package/src/clipen/provider_registry.py +9 -20
- package/src/clipen/providers/account.py +86 -35
- package/src/clipen/providers/claude.py +59 -25
- package/src/clipen/providers/claude_editing.py +14 -7
- package/src/clipen/providers/codex.py +73 -118
- package/src/clipen/providers/codex_editing.py +2 -2
- package/src/clipen/providers/editing_agent.py +19 -17
- package/src/clipen/providers/recovery.py +7 -8
- package/src/clipen/rendering/cover.py +18 -5
- package/src/clipen/rendering/custom_components.py +167 -79
- package/src/clipen/rendering/custom_render.py +62 -41
- package/src/clipen/rendering/production_effects.py +77 -45
- package/src/clipen/rendering/program_components.py +134 -73
- package/src/clipen/rendering/program_creator.py +432 -277
- package/src/clipen/rendering/program_identities.py +277 -182
- package/src/clipen/rendering/program_motion.py +140 -95
- package/src/clipen/rendering/program_studio.py +175 -116
- package/src/clipen/rendering/program_styles.py +231 -145
- package/src/clipen/rendering/program_subtitles.py +71 -34
- package/src/clipen/rendering/renderer.py +150 -121
- package/src/clipen/rendering/storage.py +9 -22
- package/src/clipen/rendering/titles.py +193 -86
- package/src/clipen/skills/__init__.py +1 -0
- package/src/clipen/skills/catalog.py +151 -55
- package/src/clipen/skills/library.py +13 -7
- package/src/clipen/skills/package.py +46 -23
- package/src/clipen/skills/visual_styles.py +29 -18
- package/src/clipen/workspace.py +15 -44
- package/install +0 -25
- package/src/clipen/planning/__init__.py +0 -9
- package/uninstall +0 -25
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from dataclasses import replace
|
|
6
|
-
from fractions import Fraction
|
|
7
5
|
import json
|
|
8
6
|
import math
|
|
7
|
+
from dataclasses import replace
|
|
8
|
+
from fractions import Fraction
|
|
9
9
|
from pathlib import Path
|
|
10
10
|
from typing import Callable, Mapping
|
|
11
11
|
|
|
12
12
|
from clipen.analysis import ArtifactStore
|
|
13
|
+
from clipen.candidates import SourceCandidate
|
|
13
14
|
from clipen.domain import (
|
|
14
15
|
ClipSource,
|
|
15
16
|
EffectRequest,
|
|
@@ -18,7 +19,6 @@ from clipen.domain import (
|
|
|
18
19
|
Track,
|
|
19
20
|
TrackKind,
|
|
20
21
|
)
|
|
21
|
-
from clipen.planning.models import PlanningCandidate
|
|
22
22
|
from clipen.projects import ProjectError
|
|
23
23
|
from clipen.projects.models import validate_project_id
|
|
24
24
|
from clipen.projects.storage import utc_now
|
|
@@ -30,10 +30,10 @@ from .agent_models import (
|
|
|
30
30
|
bounded_text,
|
|
31
31
|
)
|
|
32
32
|
from .agent_repository import EditAgentRepository
|
|
33
|
-
from .
|
|
33
|
+
from .evidence_jobs import EvidenceTools
|
|
34
34
|
from .production_catalog import EXTRA_NAMES
|
|
35
|
+
from .production_tools import ProductionTools
|
|
35
36
|
from .skill_tools import SkillTools, SourceContext
|
|
36
|
-
from .evidence_jobs import EvidenceTools
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
@@ -74,37 +74,63 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
74
74
|
handlers["edit_component"] = self._edit_component
|
|
75
75
|
handlers["set_component_text"] = self._edit_component
|
|
76
76
|
handlers["edit_component_look"] = self._edit_component_look
|
|
77
|
-
handler = (lambda args: self.production_call(name,args)) if name in EXTRA_NAMES else handlers.get(name)
|
|
77
|
+
handler = (lambda args: self.production_call(name, args)) if name in EXTRA_NAMES else handlers.get(name)
|
|
78
78
|
if handler is None:
|
|
79
79
|
raise ProjectError("tool_not_allowed", "這個工具未獲 Clipen 授權。", status_code=404)
|
|
80
80
|
if not isinstance(arguments, Mapping):
|
|
81
81
|
raise ProjectError("agent_input_invalid", "工具參數必須是物件。", status_code=422)
|
|
82
82
|
arguments = dict(arguments)
|
|
83
|
-
self._expected_revision_id = arguments.pop(
|
|
84
|
-
mutation_id = arguments.pop(
|
|
83
|
+
self._expected_revision_id = arguments.pop("expected_revision_id", None)
|
|
84
|
+
mutation_id = arguments.pop("mutation_id", None) if name != "read_mutation_receipt" else None
|
|
85
85
|
from .tool_receipts import TIMELINE_MUTATIONS, begin_receipt, finish_receipt
|
|
86
|
+
|
|
86
87
|
if name in TIMELINE_MUTATIONS and (self._expected_revision_id is None or mutation_id is None):
|
|
87
|
-
raise ProjectError(
|
|
88
|
+
raise ProjectError(
|
|
89
|
+
"mutation_guard_required", "修改前請提供目前 expected_revision_id 與本次 mutation_id。", status_code=422
|
|
90
|
+
)
|
|
88
91
|
if mutation_id is not None:
|
|
89
92
|
if name not in TIMELINE_MUTATIONS:
|
|
90
|
-
raise ProjectError(
|
|
91
|
-
replay=begin_receipt(self,name,arguments,self._expected_revision_id,mutation_id)
|
|
92
|
-
if replay is not None:
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
raise ProjectError("agent_input_invalid", "這個讀取/工作工具不接受 mutation_id。", status_code=422)
|
|
94
|
+
replay = begin_receipt(self, name, arguments, self._expected_revision_id, mutation_id)
|
|
95
|
+
if replay is not None:
|
|
96
|
+
return replay
|
|
97
|
+
elif (
|
|
98
|
+
self._expected_revision_id is not None
|
|
99
|
+
and self._expected_revision_id != self.repository.current_revision(self.project_id, self.run_id).revision_id
|
|
100
|
+
):
|
|
101
|
+
raise ProjectError("revision_conflict", "作品版本已更新,請先讀取目前版本。", status_code=409)
|
|
95
102
|
try:
|
|
96
|
-
if not getattr(self, "_user_edit", False):
|
|
103
|
+
if not getattr(self, "_user_edit", False):
|
|
104
|
+
self.repository.consume_tool_call(self.project_id, self.run_id, name)
|
|
97
105
|
result = handler(arguments)
|
|
98
106
|
except Exception as error:
|
|
99
|
-
if mutation_id is not None:
|
|
107
|
+
if mutation_id is not None:
|
|
108
|
+
finish_receipt(self, mutation_id, error=error)
|
|
100
109
|
with self.repository.projects.connect(self.project_id) as db:
|
|
101
|
-
self.repository._append_event(
|
|
110
|
+
self.repository._append_event(
|
|
111
|
+
db,
|
|
112
|
+
self.run_id,
|
|
113
|
+
"tool_failed",
|
|
114
|
+
{"tool": name, "arguments": dict(arguments), "error_code": getattr(error, "code", "tool_failed")},
|
|
115
|
+
utc_now(),
|
|
116
|
+
)
|
|
102
117
|
raise
|
|
103
|
-
if mutation_id is not None:
|
|
118
|
+
if mutation_id is not None:
|
|
119
|
+
finish_receipt(self, mutation_id, result=result)
|
|
104
120
|
with self.repository.projects.connect(self.project_id) as db:
|
|
105
|
-
self.repository._append_event(
|
|
121
|
+
self.repository._append_event(
|
|
122
|
+
db,
|
|
123
|
+
self.run_id,
|
|
124
|
+
"tool_completed",
|
|
125
|
+
{
|
|
126
|
+
"tool": name,
|
|
127
|
+
"arguments": dict(arguments),
|
|
128
|
+
"authority": "user" if getattr(self, "_user_edit", False) else "model",
|
|
129
|
+
},
|
|
130
|
+
utc_now(),
|
|
131
|
+
)
|
|
106
132
|
return ToolResult(
|
|
107
|
-
{**result.payload, "budget": self.repository.get(self.project_id,self.run_id).to_public()["budget"]},
|
|
133
|
+
{**result.payload, "budget": self.repository.get(self.project_id, self.run_id).to_public()["budget"]},
|
|
108
134
|
result.images,
|
|
109
135
|
)
|
|
110
136
|
|
|
@@ -114,12 +140,18 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
114
140
|
def _get_edit_status(self, arguments: Mapping[str, object]) -> ToolResult:
|
|
115
141
|
self._require_keys(arguments, set())
|
|
116
142
|
session = self._session_value()
|
|
117
|
-
return ToolResult(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
143
|
+
return ToolResult(
|
|
144
|
+
{
|
|
145
|
+
**self.repository.get(self.project_id, self.run_id).to_public(),
|
|
146
|
+
"mode": "skill_production",
|
|
147
|
+
"intent": session["intent"],
|
|
148
|
+
"skill": self._skill_summary(),
|
|
149
|
+
"creative_direction": self.repository.creative_direction(self.project_id, self.run_id),
|
|
150
|
+
"source_count": len(session["sources"]),
|
|
151
|
+
"evidence_coverage": "Unknown until inspected; no prior analysis or plan required.",
|
|
152
|
+
"next_step": "Read read_production_skill(resource='SKILL.md'), then explore sources and decide your workflow.",
|
|
153
|
+
}
|
|
154
|
+
)
|
|
123
155
|
|
|
124
156
|
def _search_media(self, arguments: Mapping[str, object]) -> ToolResult:
|
|
125
157
|
self._require_keys(arguments, set(), optional={"query", "limit", "offset"})
|
|
@@ -128,30 +160,31 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
128
160
|
if isinstance(limit, bool) or not isinstance(limit, int) or not 1 <= limit <= 50:
|
|
129
161
|
raise ProjectError("agent_input_invalid", "搜尋筆數必須介於 1 到 50。", status_code=422)
|
|
130
162
|
candidates = self._context_value().candidates + self._custom_candidates()
|
|
131
|
-
offset = arguments.get(
|
|
132
|
-
if isinstance(offset,bool) or not isinstance(offset,int) or not 0 <= offset <= 100000:
|
|
133
|
-
raise ProjectError(
|
|
163
|
+
offset = arguments.get("offset", 0)
|
|
164
|
+
if isinstance(offset, bool) or not isinstance(offset, int) or not 0 <= offset <= 100000:
|
|
165
|
+
raise ProjectError("agent_input_invalid", "分頁位置無效。", status_code=422)
|
|
134
166
|
if query:
|
|
135
167
|
candidates = tuple(
|
|
136
168
|
item
|
|
137
169
|
for item in candidates
|
|
138
|
-
if query
|
|
170
|
+
if query
|
|
171
|
+
in " ".join(
|
|
139
172
|
filter(None, (item.display_name, item.evidence_summary, item.transcript_excerpt))
|
|
140
173
|
).casefold()
|
|
141
174
|
)
|
|
142
175
|
return ToolResult(
|
|
143
176
|
{
|
|
144
|
-
"candidates": [item.to_provider() for item in candidates[offset:offset+limit]],
|
|
145
|
-
"returned": len(candidates[offset:offset+limit]),
|
|
146
|
-
"has_more": len(candidates) > offset+limit,
|
|
147
|
-
"next_offset": offset+limit if len(candidates)>offset+limit else None,
|
|
177
|
+
"candidates": [item.to_provider() for item in candidates[offset : offset + limit]],
|
|
178
|
+
"returned": len(candidates[offset : offset + limit]),
|
|
179
|
+
"has_more": len(candidates) > offset + limit,
|
|
180
|
+
"next_offset": offset + limit if len(candidates) > offset + limit else None,
|
|
148
181
|
"limitations": list(self._context_value().limitations),
|
|
149
182
|
}
|
|
150
183
|
)
|
|
151
184
|
|
|
152
185
|
def _inspect_clip(self, arguments: Mapping[str, object]) -> ToolResult:
|
|
153
186
|
self._require_keys(arguments, {"candidate_id"})
|
|
154
|
-
if self._inspection_count >= self.repository.get(self.project_id,self.run_id).max_tool_calls:
|
|
187
|
+
if self._inspection_count >= self.repository.get(self.project_id, self.run_id).max_tool_calls:
|
|
155
188
|
raise ProjectError(
|
|
156
189
|
"inspection_budget_exhausted",
|
|
157
190
|
"本次素材檢視已達工具預算上限。",
|
|
@@ -190,38 +223,69 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
190
223
|
filtered = track_kind is not None or any(v is not None for v in bounds)
|
|
191
224
|
if filtered:
|
|
192
225
|
timeline["tracks"] = [
|
|
193
|
-
{
|
|
194
|
-
|
|
195
|
-
|
|
226
|
+
{
|
|
227
|
+
**track,
|
|
228
|
+
"items": [
|
|
229
|
+
item
|
|
230
|
+
for item in track["items"]
|
|
231
|
+
if item["start_frame"] < end and start < item["start_frame"] + item["duration_frames"]
|
|
232
|
+
],
|
|
233
|
+
}
|
|
234
|
+
for track in timeline["tracks"]
|
|
235
|
+
if track_kind is None or track["kind"] == track_kind
|
|
236
|
+
]
|
|
196
237
|
payload["window"] = {"track": track_kind, "from_frame": start, "to_frame": end}
|
|
197
238
|
if len(json.dumps(payload, ensure_ascii=False)) <= self._SEQUENCE_CHARACTERS:
|
|
198
239
|
return ToolResult(payload)
|
|
199
240
|
# Too large for one read: return an outline and how to read it in parts.
|
|
200
241
|
seconds = timeline["duration_frames"] / fps
|
|
201
|
-
outline = [
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
242
|
+
outline = [
|
|
243
|
+
{
|
|
244
|
+
"track_id": track["track_id"],
|
|
245
|
+
"kind": track["kind"],
|
|
246
|
+
"item_count": len(track["items"]),
|
|
247
|
+
"items": [
|
|
248
|
+
{
|
|
249
|
+
"item_id": item["item_id"],
|
|
250
|
+
"start_frame": item["start_frame"],
|
|
251
|
+
"duration_frames": item["duration_frames"],
|
|
252
|
+
**({"text": item["text"][:40]} if "text" in item else {}),
|
|
253
|
+
}
|
|
254
|
+
for item in track["items"]
|
|
255
|
+
][:200],
|
|
256
|
+
}
|
|
257
|
+
for track in timeline["tracks"]
|
|
258
|
+
]
|
|
259
|
+
span = max(
|
|
260
|
+
10, round(seconds * self._SEQUENCE_CHARACTERS / max(1, len(json.dumps(payload, ensure_ascii=False))) / 2)
|
|
261
|
+
)
|
|
207
262
|
payload["timeline"] = {key: value for key, value in timeline.items() if key != "tracks"}
|
|
208
263
|
payload["outline"] = outline
|
|
209
|
-
payload["read_in_parts"] = (
|
|
210
|
-
|
|
211
|
-
|
|
264
|
+
payload["read_in_parts"] = (
|
|
265
|
+
f"The full timeline is too large for one read. Call inspect_sequence with track "
|
|
266
|
+
f"(video, title or audio) and/or from_seconds/to_seconds; windows of about {span} "
|
|
267
|
+
f"seconds fit. The outline lists every item with its timing."
|
|
268
|
+
)
|
|
212
269
|
if len(json.dumps(payload, ensure_ascii=False)) > self._SEQUENCE_CHARACTERS:
|
|
213
270
|
for track in outline:
|
|
214
|
-
track["items"] = [
|
|
215
|
-
|
|
271
|
+
track["items"] = [
|
|
272
|
+
{"item_id": i["item_id"], "start_frame": i["start_frame"], "duration_frames": i["duration_frames"]}
|
|
273
|
+
for i in track["items"]
|
|
274
|
+
]
|
|
216
275
|
return ToolResult(payload)
|
|
217
276
|
|
|
218
277
|
def _replace_sequence(self, arguments: Mapping[str, object]) -> ToolResult:
|
|
219
|
-
self._require_keys(arguments, {"clips", "summary"},optional={
|
|
220
|
-
if self._session_value()[
|
|
221
|
-
raise ProjectError(
|
|
278
|
+
self._require_keys(arguments, {"clips", "summary"}, optional={"reprise_reason"})
|
|
279
|
+
if self._session_value()["intent"].get("latest_revision_request") and self._timeline().duration_frames > 0:
|
|
280
|
+
raise ProjectError(
|
|
281
|
+
"incremental_revision_required",
|
|
282
|
+
"這是既有影片的修訂,請使用裁切、替換單一片段、重排或元件工具保留其他內容,不可清空重建整條時間軸。",
|
|
283
|
+
status_code=409,
|
|
284
|
+
)
|
|
222
285
|
selections = arguments["clips"]
|
|
223
286
|
from .production_limits import limits_for
|
|
224
|
-
|
|
287
|
+
|
|
288
|
+
limits = limits_for(self)
|
|
225
289
|
if not isinstance(selections, list) or not 1 <= len(selections) <= limits.clips:
|
|
226
290
|
raise ProjectError(
|
|
227
291
|
"agent_input_invalid",
|
|
@@ -230,12 +294,11 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
230
294
|
)
|
|
231
295
|
parsed = [self._trimmed_candidate(value) for value in selections]
|
|
232
296
|
identities = [identity for _, _, identity in parsed]
|
|
233
|
-
reprise=arguments.get(
|
|
234
|
-
if reprise is not None:
|
|
297
|
+
reprise = arguments.get("reprise_reason")
|
|
298
|
+
if reprise is not None:
|
|
299
|
+
reprise = bounded_text(reprise, "預告/回扣用途", 500)
|
|
235
300
|
if len(identities) != len(set(identities)) and not reprise:
|
|
236
|
-
raise ProjectError(
|
|
237
|
-
"agent_input_invalid", "不能重複使用完全相同的來源範圍。", status_code=422
|
|
238
|
-
)
|
|
301
|
+
raise ProjectError("agent_input_invalid", "不能重複使用完全相同的來源範圍。", status_code=422)
|
|
239
302
|
candidates = [candidate for candidate, _, _ in parsed]
|
|
240
303
|
if any(item.media_kind != "video" for item in candidates):
|
|
241
304
|
raise ProjectError("agent_input_invalid", "主畫面只能使用影片候選片段。", status_code=422)
|
|
@@ -325,37 +388,74 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
325
388
|
|
|
326
389
|
def _undo_revision(self, arguments: Mapping[str, object]) -> ToolResult:
|
|
327
390
|
self._require_keys(arguments, set())
|
|
328
|
-
return ToolResult(
|
|
391
|
+
return ToolResult(
|
|
392
|
+
{
|
|
393
|
+
"revision": self.repository.undo(
|
|
394
|
+
self.project_id, self.run_id, expected_revision_id=self._expected_revision_id
|
|
395
|
+
).to_public()
|
|
396
|
+
}
|
|
397
|
+
)
|
|
329
398
|
|
|
330
399
|
def _finish_edit(self, arguments: Mapping[str, object]) -> ToolResult:
|
|
331
400
|
self._require_keys(arguments, {"summary"}, optional={"changes", "notes", "not_done"})
|
|
332
|
-
issues=self._production_validate_sequence({}).payload[
|
|
401
|
+
issues = self._production_validate_sequence({}).payload["issues"]
|
|
333
402
|
if issues:
|
|
334
|
-
raise ProjectError(
|
|
403
|
+
raise ProjectError(
|
|
404
|
+
"agent_sequence_invalid",
|
|
405
|
+
"時間軸或交付條件尚未通過,請先呼叫 validate_sequence 查看實際範圍與待修項目。",
|
|
406
|
+
status_code=422,
|
|
407
|
+
)
|
|
335
408
|
# Production bounds, including minimum delivery duration, are reported by validate_sequence.
|
|
336
409
|
from .production_preview import finish_review_status
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
410
|
+
|
|
411
|
+
review = finish_review_status(self)
|
|
412
|
+
if not review["reviewed_revision"]:
|
|
413
|
+
raise ProjectError(
|
|
414
|
+
"agent_preview_review_required",
|
|
415
|
+
"請先逐鏡檢視目前預覽及文字,使用 review_cut 記錄判斷並修正未解決問題;validate_sequence 會列出缺少的取樣。",
|
|
416
|
+
status_code=409,
|
|
417
|
+
)
|
|
340
418
|
from .change_report import challenge, check_report, unfinished
|
|
341
|
-
|
|
419
|
+
|
|
420
|
+
report = check_report(arguments, self._session_value()["intent"])
|
|
342
421
|
if unfinished(report) and not self._challenged():
|
|
343
422
|
raise challenge(report)
|
|
344
|
-
exported=self._production_export_edit({}).payload
|
|
345
|
-
return ToolResult(
|
|
423
|
+
exported = self._production_export_edit({}).payload
|
|
424
|
+
return ToolResult(
|
|
425
|
+
{
|
|
426
|
+
**self.repository.finish(
|
|
427
|
+
self.project_id,
|
|
428
|
+
self.run_id,
|
|
429
|
+
arguments["summary"],
|
|
430
|
+
expected_revision_id=self._expected_revision_id,
|
|
431
|
+
report=report,
|
|
432
|
+
).to_public(),
|
|
433
|
+
"review": review,
|
|
434
|
+
"export": exported,
|
|
435
|
+
}
|
|
436
|
+
)
|
|
346
437
|
|
|
347
438
|
def _challenged(self) -> bool:
|
|
348
439
|
"""Whether finish_edit already asked, during this request, to finish what the report left undone."""
|
|
349
440
|
from .change_report import UNFINISHED
|
|
441
|
+
|
|
350
442
|
with self.repository.projects.connect(self.project_id) as db:
|
|
351
|
-
start = db.execute(
|
|
352
|
-
|
|
353
|
-
|
|
443
|
+
start = db.execute(
|
|
444
|
+
"SELECT COALESCE(MAX(sequence),-1) FROM edit_agent_events WHERE run_id=? AND event_type='refinement_requested'",
|
|
445
|
+
(self.run_id,),
|
|
446
|
+
).fetchone()[0]
|
|
447
|
+
rows = db.execute(
|
|
448
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='tool_failed' AND sequence>?",
|
|
449
|
+
(self.run_id, start),
|
|
450
|
+
).fetchall()
|
|
451
|
+
return any(json.loads(r["payload_json"]).get("error_code") == UNFINISHED for r in rows)
|
|
354
452
|
|
|
355
|
-
def _candidate(self, value: object) ->
|
|
453
|
+
def _candidate(self, value: object) -> SourceCandidate:
|
|
356
454
|
if not isinstance(value, str):
|
|
357
455
|
raise ProjectError("agent_input_invalid", "候選片段識別資訊無效。", status_code=422)
|
|
358
|
-
candidate = self._context_value().candidate_map().get(value) or next(
|
|
456
|
+
candidate = self._context_value().candidate_map().get(value) or next(
|
|
457
|
+
(c for c in self._custom_candidates() if c.candidate_id == value), None
|
|
458
|
+
)
|
|
359
459
|
if candidate is None:
|
|
360
460
|
raise ProjectError("candidate_not_found", "找不到指定的候選片段。", status_code=404)
|
|
361
461
|
return candidate
|
|
@@ -389,11 +489,7 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
389
489
|
)
|
|
390
490
|
for key, value in parameters.items():
|
|
391
491
|
minimum, maximum = allowed[key]
|
|
392
|
-
if (
|
|
393
|
-
isinstance(value, bool)
|
|
394
|
-
or not isinstance(value, (int, float))
|
|
395
|
-
or not minimum <= float(value) <= maximum
|
|
396
|
-
):
|
|
492
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)) or not minimum <= float(value) <= maximum:
|
|
397
493
|
raise ProjectError(
|
|
398
494
|
"agent_input_invalid",
|
|
399
495
|
"效果參數超出安全範圍。",
|
|
@@ -412,17 +508,13 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
412
508
|
}
|
|
413
509
|
return defaults[effect_id]
|
|
414
510
|
|
|
415
|
-
def _trimmed_candidate(
|
|
416
|
-
self, value: object
|
|
417
|
-
) -> tuple[PlanningCandidate, SourceSpan, tuple[str, int, int]]:
|
|
511
|
+
def _trimmed_candidate(self, value: object) -> tuple[SourceCandidate, SourceSpan, tuple[str, int, int]]:
|
|
418
512
|
if not isinstance(value, Mapping) or set(value) != {
|
|
419
513
|
"candidate_id",
|
|
420
514
|
"start_offset_seconds",
|
|
421
515
|
"duration_seconds",
|
|
422
516
|
}:
|
|
423
|
-
raise ProjectError(
|
|
424
|
-
"agent_input_invalid", "精剪鏡頭內容無效。", status_code=422
|
|
425
|
-
)
|
|
517
|
+
raise ProjectError("agent_input_invalid", "精剪鏡頭內容無效。", status_code=422)
|
|
426
518
|
candidate = self._candidate(value["candidate_id"])
|
|
427
519
|
start = self._finite_fraction(value["start_offset_seconds"], "鏡頭入點")
|
|
428
520
|
duration = self._finite_fraction(value["duration_seconds"], "鏡頭長度")
|
|
@@ -455,19 +547,11 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
455
547
|
|
|
456
548
|
@staticmethod
|
|
457
549
|
def _finite_fraction(value: object, label: str) -> Fraction:
|
|
458
|
-
if (
|
|
459
|
-
|
|
460
|
-
or not isinstance(value, (int, float))
|
|
461
|
-
or not math.isfinite(float(value))
|
|
462
|
-
):
|
|
463
|
-
raise ProjectError(
|
|
464
|
-
"agent_input_invalid", f"{label}必須是有限數字。", status_code=422
|
|
465
|
-
)
|
|
550
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(float(value)):
|
|
551
|
+
raise ProjectError("agent_input_invalid", f"{label}必須是有限數字。", status_code=422)
|
|
466
552
|
return Fraction(str(value))
|
|
467
553
|
|
|
468
|
-
def _candidate_images(
|
|
469
|
-
self, candidate: PlanningCandidate
|
|
470
|
-
) -> tuple[tuple[Path, ...], list[dict[str, object]]]:
|
|
554
|
+
def _candidate_images(self, candidate: SourceCandidate) -> tuple[tuple[Path, ...], list[dict[str, object]]]:
|
|
471
555
|
with self.repository.projects.connect(self.project_id) as database:
|
|
472
556
|
rows = database.execute(
|
|
473
557
|
"SELECT results.result_json FROM evidence_results results "
|
|
@@ -491,9 +575,7 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
491
575
|
except (json.JSONDecodeError, TypeError, ValueError):
|
|
492
576
|
continue
|
|
493
577
|
inside = [
|
|
494
|
-
item
|
|
495
|
-
for item in artifacts
|
|
496
|
-
if int(candidate.source.start_pts) <= item[2] <= int(candidate.source.end_pts)
|
|
578
|
+
item for item in artifacts if int(candidate.source.start_pts) <= item[2] <= int(candidate.source.end_pts)
|
|
497
579
|
]
|
|
498
580
|
# A nearby frame from another candidate can look plausible while pointing
|
|
499
581
|
# the model at an invalid offset. Returning no image is safer than mixing
|
|
@@ -506,8 +588,7 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
506
588
|
try:
|
|
507
589
|
paths.append(self.artifacts.path(self.artifacts.get(self.project_id, artifact_id)))
|
|
508
590
|
offset = Fraction(
|
|
509
|
-
(pts - int(candidate.source.start_pts))
|
|
510
|
-
* candidate.source.time_base.numerator,
|
|
591
|
+
(pts - int(candidate.source.start_pts)) * candidate.source.time_base.numerator,
|
|
511
592
|
candidate.source.time_base.denominator,
|
|
512
593
|
)
|
|
513
594
|
samples.append(
|