@clipen/clipen-cli 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +89 -2
- package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
- package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
- package/apps/web/dist/favicon.svg +1 -0
- package/apps/web/dist/index.html +16 -0
- package/bin/clipen.js +157 -0
- package/clipen +18 -0
- package/install +25 -0
- package/package.json +55 -4
- package/pyproject.toml +44 -0
- package/requirements/asr-runtime.txt +13 -0
- package/requirements/dev.txt +2 -0
- package/requirements/runtime.txt +20 -0
- package/src/clipen/__init__.py +3 -0
- package/src/clipen/analysis/__init__.py +89 -0
- package/src/clipen/analysis/artifacts.py +410 -0
- package/src/clipen/analysis/audio.py +394 -0
- package/src/clipen/analysis/evidence.py +102 -0
- package/src/clipen/analysis/evidence_service.py +929 -0
- package/src/clipen/analysis/image_similarity.py +134 -0
- package/src/clipen/analysis/keyframes.py +159 -0
- package/src/clipen/analysis/models.py +228 -0
- package/src/clipen/analysis/qwen_worker.py +594 -0
- package/src/clipen/analysis/resources.py +22 -0
- package/src/clipen/analysis/runtime.py +62 -0
- package/src/clipen/analysis/service.py +594 -0
- package/src/clipen/analysis/setup.py +921 -0
- package/src/clipen/analysis/setup_cli.py +107 -0
- package/src/clipen/analysis/storage.py +1864 -0
- package/src/clipen/analysis/transcription.py +906 -0
- package/src/clipen/analysis/visual.py +237 -0
- package/src/clipen/annotations/__init__.py +13 -0
- package/src/clipen/annotations/models.py +22 -0
- package/src/clipen/annotations/storage.py +428 -0
- package/src/clipen/annotations/suggestions.py +115 -0
- package/src/clipen/asr_release.py +132 -0
- package/src/clipen/bootstrap.py +978 -0
- package/src/clipen/candidates.py +222 -0
- package/src/clipen/cli.py +84 -0
- package/src/clipen/controller/__init__.py +17 -0
- package/src/clipen/controller/app.py +1657 -0
- package/src/clipen/controller/server.py +533 -0
- package/src/clipen/domain/__init__.py +30 -0
- package/src/clipen/domain/errors.py +5 -0
- package/src/clipen/domain/media_time.py +110 -0
- package/src/clipen/domain/timeline.py +582 -0
- package/src/clipen/domain/validation.py +14 -0
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
- package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
- package/src/clipen/editing/README.md +115 -0
- package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
- package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
- package/src/clipen/editing/__init__.py +15 -0
- package/src/clipen/editing/agent.py +13 -0
- package/src/clipen/editing/agent_models.py +127 -0
- package/src/clipen/editing/agent_repository.py +978 -0
- package/src/clipen/editing/agent_tools.py +613 -0
- package/src/clipen/editing/alignment.py +150 -0
- package/src/clipen/editing/alignment_setup.py +156 -0
- package/src/clipen/editing/alignment_worker.py +24 -0
- package/src/clipen/editing/change_report.py +128 -0
- package/src/clipen/editing/compiler.py +40 -0
- package/src/clipen/editing/component_looks.py +131 -0
- package/src/clipen/editing/component_review.py +74 -0
- package/src/clipen/editing/coordinator.py +497 -0
- package/src/clipen/editing/editorial_review.py +309 -0
- package/src/clipen/editing/evidence_jobs.py +552 -0
- package/src/clipen/editing/history_changes.py +192 -0
- package/src/clipen/editing/music_choices.py +18 -0
- package/src/clipen/editing/production_catalog.py +629 -0
- package/src/clipen/editing/production_limits.py +85 -0
- package/src/clipen/editing/production_media.py +435 -0
- package/src/clipen/editing/production_preview.py +373 -0
- package/src/clipen/editing/production_progress.py +236 -0
- package/src/clipen/editing/production_requirements.py +117 -0
- package/src/clipen/editing/production_tools.py +1198 -0
- package/src/clipen/editing/program_audio.py +248 -0
- package/src/clipen/editing/program_direction.py +83 -0
- package/src/clipen/editing/program_story.py +91 -0
- package/src/clipen/editing/program_subtitles.py +232 -0
- package/src/clipen/editing/programme_review.py +121 -0
- package/src/clipen/editing/prompt_history.py +84 -0
- package/src/clipen/editing/recut.py +167 -0
- package/src/clipen/editing/refinement_references.py +278 -0
- package/src/clipen/editing/resolve_export.py +847 -0
- package/src/clipen/editing/resolve_titles.py +291 -0
- package/src/clipen/editing/skill_tools.py +951 -0
- package/src/clipen/editing/source_dialogue.py +192 -0
- package/src/clipen/editing/speech_coverage.py +50 -0
- package/src/clipen/editing/speech_quality.py +11 -0
- package/src/clipen/editing/tool_receipts.py +98 -0
- package/src/clipen/editing/versions.py +219 -0
- package/src/clipen/editing/visual_preview.py +189 -0
- package/src/clipen/editing/workbench.py +136 -0
- package/src/clipen/filesystem.py +25 -0
- package/src/clipen/finishing/README.md +103 -0
- package/src/clipen/finishing/__init__.py +1 -0
- package/src/clipen/finishing/audio.py +188 -0
- package/src/clipen/finishing/catalog.py +264 -0
- package/src/clipen/finishing/models.py +14 -0
- package/src/clipen/finishing/renderer.py +45 -0
- package/src/clipen/mcp_editing/__init__.py +5 -0
- package/src/clipen/mcp_editing/__main__.py +42 -0
- package/src/clipen/mcp_editing/server.py +396 -0
- package/src/clipen/media/__init__.py +50 -0
- package/src/clipen/media/discovery.py +253 -0
- package/src/clipen/media/models.py +349 -0
- package/src/clipen/media/preview.py +137 -0
- package/src/clipen/media/probe.py +418 -0
- package/src/clipen/media/service.py +304 -0
- package/src/clipen/media/storage.py +694 -0
- package/src/clipen/music_vocabulary.py +34 -0
- package/src/clipen/power.py +28 -0
- package/src/clipen/projects/__init__.py +26 -0
- package/src/clipen/projects/agent_schema.py +94 -0
- package/src/clipen/projects/annotation_schema.py +40 -0
- package/src/clipen/projects/deletion.py +256 -0
- package/src/clipen/projects/evidence_schema.py +52 -0
- package/src/clipen/projects/finishing_schema.py +36 -0
- package/src/clipen/projects/models.py +189 -0
- package/src/clipen/projects/picker.py +232 -0
- package/src/clipen/projects/preview_schema.py +29 -0
- package/src/clipen/projects/service.py +159 -0
- package/src/clipen/projects/storage.py +1458 -0
- package/src/clipen/projects/timeline_schema.py +32 -0
- package/src/clipen/projects/validation_schema.py +28 -0
- package/src/clipen/provider_registry.py +77 -0
- package/src/clipen/providers/__init__.py +43 -0
- package/src/clipen/providers/account.py +245 -0
- package/src/clipen/providers/claude.py +409 -0
- package/src/clipen/providers/claude_editing.py +118 -0
- package/src/clipen/providers/codex.py +991 -0
- package/src/clipen/providers/codex_editing.py +91 -0
- package/src/clipen/providers/editing_agent.py +567 -0
- package/src/clipen/providers/errors.py +51 -0
- package/src/clipen/providers/recovery.py +269 -0
- package/src/clipen/py.typed +1 -0
- package/src/clipen/rendering/__init__.py +12 -0
- package/src/clipen/rendering/cover.py +139 -0
- package/src/clipen/rendering/custom_components.py +328 -0
- package/src/clipen/rendering/custom_render.py +218 -0
- package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/manifest.json +145 -0
- package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
- package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
- package/src/clipen/rendering/production_effects.py +96 -0
- package/src/clipen/rendering/program_components.py +254 -0
- package/src/clipen/rendering/program_creator.py +804 -0
- package/src/clipen/rendering/program_identities.py +350 -0
- package/src/clipen/rendering/program_motion.py +186 -0
- package/src/clipen/rendering/program_studio.py +227 -0
- package/src/clipen/rendering/program_styles.py +321 -0
- package/src/clipen/rendering/program_subtitles.py +89 -0
- package/src/clipen/rendering/renderer.py +737 -0
- package/src/clipen/rendering/storage.py +230 -0
- package/src/clipen/rendering/titles.py +467 -0
- package/src/clipen/skills/__init__.py +5 -0
- package/src/clipen/skills/builtin/SKILL.md +72 -0
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
- package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
- package/src/clipen/skills/builtin/components.json +133 -0
- package/src/clipen/skills/builtin/font_sources.json +20 -0
- package/src/clipen/skills/builtin/font_styles.json +329 -0
- package/src/clipen/skills/builtin/manifest.json +32 -0
- package/src/clipen/skills/builtin/presets.json +8 -0
- package/src/clipen/skills/builtin/references/captions.md +14 -0
- package/src/clipen/skills/builtin/references/channel-design.md +37 -0
- package/src/clipen/skills/builtin/references/editing.md +30 -0
- package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/graphics.md +59 -0
- package/src/clipen/skills/builtin/references/review.md +16 -0
- package/src/clipen/skills/builtin/references/sound.md +8 -0
- package/src/clipen/skills/builtin/references/story.md +7 -0
- package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
- package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/templates.json +284 -0
- package/src/clipen/skills/builtin/visual_styles.json +1074 -0
- package/src/clipen/skills/catalog.py +314 -0
- package/src/clipen/skills/library.py +137 -0
- package/src/clipen/skills/package.py +254 -0
- package/src/clipen/skills/visual_styles.py +55 -0
- package/src/clipen/workspace.py +181 -0
- package/uninstall +25 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"""Revision-bound render/review tools; no model-visible filesystem handles."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import secrets
|
|
7
|
+
import sys
|
|
8
|
+
import threading
|
|
9
|
+
import time
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from clipen.finishing.audio import run_process
|
|
13
|
+
from clipen.finishing.renderer import verify_output
|
|
14
|
+
from clipen.media import MediaPreviewRepository
|
|
15
|
+
from clipen.projects import ProjectError
|
|
16
|
+
from clipen.projects.storage import utc_now
|
|
17
|
+
from clipen.rendering import FfmpegPreviewRenderer, PreviewRenderRepository
|
|
18
|
+
|
|
19
|
+
from .agent_models import ToolResult
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _event(tools, kind, payload):
|
|
23
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
24
|
+
tools.repository._append_event(db, tools.run_id, kind, payload, utc_now())
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def render_recipe_id():
|
|
28
|
+
"""Cache executable rendering code as well as the immutable edit payload."""
|
|
29
|
+
from clipen.rendering import (
|
|
30
|
+
production_effects,
|
|
31
|
+
program_components,
|
|
32
|
+
program_identities,
|
|
33
|
+
program_motion,
|
|
34
|
+
program_studio,
|
|
35
|
+
program_styles,
|
|
36
|
+
program_subtitles,
|
|
37
|
+
renderer,
|
|
38
|
+
titles,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
from . import production_media, program_audio
|
|
42
|
+
|
|
43
|
+
digest = hashlib.sha256()
|
|
44
|
+
for module in (
|
|
45
|
+
renderer,
|
|
46
|
+
titles,
|
|
47
|
+
program_components,
|
|
48
|
+
program_motion,
|
|
49
|
+
program_styles,
|
|
50
|
+
program_studio,
|
|
51
|
+
program_identities,
|
|
52
|
+
program_subtitles,
|
|
53
|
+
production_effects,
|
|
54
|
+
program_audio,
|
|
55
|
+
production_media,
|
|
56
|
+
):
|
|
57
|
+
digest.update(Path(module.__file__).read_bytes())
|
|
58
|
+
return digest.hexdigest()
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def render_preview(tools):
|
|
62
|
+
revision = tools.repository.current_revision(tools.project_id, tools.run_id)
|
|
63
|
+
recipe_id = render_recipe_id()
|
|
64
|
+
validation = tools._production_validate_sequence({}).payload
|
|
65
|
+
issues = validation["render_issues"]
|
|
66
|
+
if issues:
|
|
67
|
+
raise ProjectError("agent_sequence_invalid", "請先使用 validate_sequence 修正時間軸。", status_code=422)
|
|
68
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
69
|
+
# The exact revision is the cache key. Polling/reviewing never rerenders it.
|
|
70
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
71
|
+
prior = db.execute(
|
|
72
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_preview' ORDER BY sequence DESC",
|
|
73
|
+
(tools.run_id,),
|
|
74
|
+
).fetchall()
|
|
75
|
+
for row in prior:
|
|
76
|
+
entry = json.loads(row["payload_json"])
|
|
77
|
+
if entry["revision_id"] == revision.revision_id and entry.get("recipe_id") == recipe_id:
|
|
78
|
+
saved = store.get(tools.project_id, entry["render_id"])
|
|
79
|
+
if saved["state"] in {"queued", "running", "succeeded"}:
|
|
80
|
+
return ToolResult({"render": saved, "revision_id": revision.revision_id, "reused": True})
|
|
81
|
+
current = store.current(tools.project_id)
|
|
82
|
+
if current and current["state"] in {"queued", "running", "cancelling"}:
|
|
83
|
+
mine = current["render_id"] in {json.loads(r["payload_json"])["render_id"] for r in prior}
|
|
84
|
+
raise ProjectError(
|
|
85
|
+
"preview_busy",
|
|
86
|
+
f"目前有預覽正在合成({current['render_id']},進度 {round(current.get('progress', 0) * 100)}%)。"
|
|
87
|
+
+ (
|
|
88
|
+
"這是本次製作的輸出:用 inspect_preview 等它完成,或用 cancel_preview 取消後再輸出。"
|
|
89
|
+
if mine
|
|
90
|
+
else "這是使用者或其他工作的輸出,請稍後再試。"
|
|
91
|
+
),
|
|
92
|
+
status_code=409,
|
|
93
|
+
)
|
|
94
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
95
|
+
db.execute("BEGIN IMMEDIATE")
|
|
96
|
+
run = tools.repository._read_run(db, tools.run_id)
|
|
97
|
+
if not getattr(tools, "_user_edit", False) and run.preview_renders >= run.max_preview_renders:
|
|
98
|
+
raise ProjectError(
|
|
99
|
+
"preview_budget_exhausted",
|
|
100
|
+
"已達本次預覽上限,請使用已完成的版本或回報尚未完成的檢視。",
|
|
101
|
+
status_code=409,
|
|
102
|
+
)
|
|
103
|
+
if not getattr(tools, "_user_edit", False):
|
|
104
|
+
db.execute("UPDATE edit_agent_runs SET preview_renders=preview_renders+1 WHERE run_id=?", (tools.run_id,))
|
|
105
|
+
db.commit()
|
|
106
|
+
request_id = (
|
|
107
|
+
("user-preview-" + secrets.token_hex(16))
|
|
108
|
+
if getattr(tools, "_user_edit", False)
|
|
109
|
+
else "agent-preview-" + tools.run_id + "-" + revision.revision_id + "-" + str(run.preview_renders + 1)
|
|
110
|
+
)
|
|
111
|
+
render = store.create(tools.project_id, request_id, revision.revision_id)
|
|
112
|
+
_event(
|
|
113
|
+
tools,
|
|
114
|
+
"production_preview",
|
|
115
|
+
{"render_id": render["render_id"], "revision_id": revision.revision_id, "recipe_id": recipe_id},
|
|
116
|
+
)
|
|
117
|
+
cancel = threading.Event()
|
|
118
|
+
if not hasattr(tools, "_preview_jobs"):
|
|
119
|
+
tools._preview_jobs = {}
|
|
120
|
+
renderer = getattr(tools, "preview_renderer", None) or FfmpegPreviewRenderer(
|
|
121
|
+
MediaPreviewRepository(tools.repository.projects), hardware_acceleration=sys.platform == "darwin"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def worker():
|
|
125
|
+
staging = final = None
|
|
126
|
+
|
|
127
|
+
def progress(value):
|
|
128
|
+
state = tools.repository.get(tools.project_id, tools.run_id).state
|
|
129
|
+
if (
|
|
130
|
+
state not in {"queued", "running"} and not getattr(tools, "_user_edit", False)
|
|
131
|
+
) or tools._cancel_event().is_set():
|
|
132
|
+
cancel.set()
|
|
133
|
+
if store.get(tools.project_id, render["render_id"])["state"] == "cancelling":
|
|
134
|
+
cancel.set()
|
|
135
|
+
store.update_progress(tools.project_id, render["render_id"], value)
|
|
136
|
+
|
|
137
|
+
try:
|
|
138
|
+
staging = store.output_path(tools.project_id, render["render_id"], staging=True)
|
|
139
|
+
final = store.output_path(tools.project_id, render["render_id"])
|
|
140
|
+
store.mark_running(tools.project_id, render["render_id"])
|
|
141
|
+
renderer.render(tools.project_id, revision.timeline, staging, cancel, progress)
|
|
142
|
+
if cancel.is_set():
|
|
143
|
+
raise ProjectError("user_cancelled", "已取消預覽。", status_code=409)
|
|
144
|
+
verify_output(staging, revision.timeline, cancel)
|
|
145
|
+
os.replace(staging, final)
|
|
146
|
+
final.chmod(0o600)
|
|
147
|
+
for suffix in (".music.wav", ".camera.wav", ".mix.wav", ".mix.json"):
|
|
148
|
+
stem = staging.with_suffix(suffix)
|
|
149
|
+
if stem.is_file():
|
|
150
|
+
os.replace(stem, final.with_suffix(suffix))
|
|
151
|
+
final.with_suffix(suffix).chmod(0o600)
|
|
152
|
+
store.complete(tools.project_id, render["render_id"], "previews/" + final.name, final.stat().st_size)
|
|
153
|
+
except Exception as error:
|
|
154
|
+
_event(
|
|
155
|
+
tools,
|
|
156
|
+
"production_preview_failed",
|
|
157
|
+
{
|
|
158
|
+
"render_id": render["render_id"],
|
|
159
|
+
"revision_id": revision.revision_id,
|
|
160
|
+
"error_code": getattr(error, "code", "agent_render_failed"),
|
|
161
|
+
"error_type": type(error).__name__,
|
|
162
|
+
"message": getattr(error, "message", "Local render failed"),
|
|
163
|
+
},
|
|
164
|
+
)
|
|
165
|
+
if final is not None:
|
|
166
|
+
final.unlink(missing_ok=True)
|
|
167
|
+
for suffix in (".music.wav", ".camera.wav", ".mix.wav", ".mix.json"):
|
|
168
|
+
final.with_suffix(suffix).unlink(missing_ok=True)
|
|
169
|
+
store.finish_unsuccessful(
|
|
170
|
+
tools.project_id,
|
|
171
|
+
render["render_id"],
|
|
172
|
+
"cancelled" if cancel.is_set() else "failed",
|
|
173
|
+
error_code=getattr(error, "code", "agent_render_failed"),
|
|
174
|
+
)
|
|
175
|
+
finally:
|
|
176
|
+
if staging is not None:
|
|
177
|
+
staging.unlink(missing_ok=True)
|
|
178
|
+
if staging is not None:
|
|
179
|
+
for suffix in (".music.wav", ".camera.wav", ".mix.wav", ".mix.json"):
|
|
180
|
+
staging.with_suffix(suffix).unlink(missing_ok=True)
|
|
181
|
+
|
|
182
|
+
thread = threading.Thread(target=worker, name="clipen-agent-preview", daemon=True)
|
|
183
|
+
tools._preview_jobs[render["render_id"]] = (cancel, thread)
|
|
184
|
+
thread.start()
|
|
185
|
+
return ToolResult(
|
|
186
|
+
{
|
|
187
|
+
"render": render,
|
|
188
|
+
"revision_id": revision.revision_id,
|
|
189
|
+
"reused": False,
|
|
190
|
+
"next": "inspect_preview with wait_seconds up to 30; do not call render_preview to poll",
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def inspect_preview(tools, args):
|
|
196
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
197
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
198
|
+
entries = [
|
|
199
|
+
json.loads(r["payload_json"])
|
|
200
|
+
for r in db.execute(
|
|
201
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_preview'",
|
|
202
|
+
(tools.run_id,),
|
|
203
|
+
)
|
|
204
|
+
]
|
|
205
|
+
entry = next((e for e in entries if e["render_id"] == args["render_id"]), None)
|
|
206
|
+
if entry is None:
|
|
207
|
+
raise ProjectError("preview_not_found", "預覽不屬於這次剪輯。", status_code=404)
|
|
208
|
+
deadline = time.monotonic() + args.get("wait_seconds", 0)
|
|
209
|
+
while True:
|
|
210
|
+
render = store.get(tools.project_id, args["render_id"])
|
|
211
|
+
if render["state"] not in {"queued", "running", "cancelling"} or time.monotonic() >= deadline:
|
|
212
|
+
break
|
|
213
|
+
tools._cancel_event().wait(min(0.2, max(0, deadline - time.monotonic())))
|
|
214
|
+
current = tools.repository.current_revision(tools.project_id, tools.run_id)
|
|
215
|
+
payload = {
|
|
216
|
+
"render": render,
|
|
217
|
+
"revision_id": entry["revision_id"],
|
|
218
|
+
"recipe_id": entry.get("recipe_id"),
|
|
219
|
+
"stale": entry["revision_id"] != current.revision_id or entry.get("recipe_id") != render_recipe_id(),
|
|
220
|
+
"coverage": "selected instants only; audio not listened to",
|
|
221
|
+
}
|
|
222
|
+
if render["state"] != "succeeded":
|
|
223
|
+
return ToolResult(payload)
|
|
224
|
+
path = store.output_path(tools.project_id, args["render_id"], prepare=False)
|
|
225
|
+
if path.is_symlink() or not path.is_file() or path.stat().st_size != render["size_bytes"]:
|
|
226
|
+
raise ProjectError("preview_missing", "預覽檔案已遺失或變更。", status_code=409)
|
|
227
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
228
|
+
row = db.execute(
|
|
229
|
+
"SELECT payload_json FROM edit_agent_revisions WHERE revision_id=? AND run_id=?",
|
|
230
|
+
(entry["revision_id"], tools.run_id),
|
|
231
|
+
).fetchone()
|
|
232
|
+
timeline = json.loads(row["payload_json"])
|
|
233
|
+
seconds = timeline["duration_frames"] * timeline["frame_rate"]["den"] / timeline["frame_rate"]["num"]
|
|
234
|
+
if any(t >= seconds for t in args["offsets_seconds"]):
|
|
235
|
+
raise ProjectError("agent_input_invalid", "檢視時間超出預覽範圍。", status_code=422)
|
|
236
|
+
images = []
|
|
237
|
+
for n, offset in enumerate(args["offsets_seconds"]):
|
|
238
|
+
image = tools._workdir("reviews") / (args["render_id"] + "-" + str(n) + "-" + str(time.time_ns()) + ".png")
|
|
239
|
+
run_process(
|
|
240
|
+
[
|
|
241
|
+
"ffmpeg",
|
|
242
|
+
"-v",
|
|
243
|
+
"error",
|
|
244
|
+
"-nostdin",
|
|
245
|
+
"-ss",
|
|
246
|
+
str(offset),
|
|
247
|
+
"-i",
|
|
248
|
+
str(path),
|
|
249
|
+
"-frames:v",
|
|
250
|
+
"1",
|
|
251
|
+
"-vf",
|
|
252
|
+
"scale=640:-2",
|
|
253
|
+
"-threads",
|
|
254
|
+
"1",
|
|
255
|
+
str(image),
|
|
256
|
+
],
|
|
257
|
+
tools._cancel_event(),
|
|
258
|
+
timeout=30,
|
|
259
|
+
)
|
|
260
|
+
if not image.is_file():
|
|
261
|
+
raise ProjectError("preview_frame_missing", "指定時間沒有可解碼畫面。", status_code=409)
|
|
262
|
+
images.append(image)
|
|
263
|
+
if images:
|
|
264
|
+
_event(
|
|
265
|
+
tools,
|
|
266
|
+
"production_review",
|
|
267
|
+
{
|
|
268
|
+
"render_id": args["render_id"],
|
|
269
|
+
"revision_id": entry["revision_id"],
|
|
270
|
+
"recipe_id": entry.get("recipe_id"),
|
|
271
|
+
"offsets_seconds": args["offsets_seconds"],
|
|
272
|
+
},
|
|
273
|
+
)
|
|
274
|
+
return ToolResult({**payload, "sample_offsets_seconds": args["offsets_seconds"]}, tuple(images))
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def finish_review_status(tools):
|
|
278
|
+
from .editorial_review import coverage_targets, text_targets
|
|
279
|
+
|
|
280
|
+
revision = tools.repository.current_revision(tools.project_id, tools.run_id)
|
|
281
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
282
|
+
entries = [
|
|
283
|
+
json.loads(r["payload_json"])
|
|
284
|
+
for r in db.execute(
|
|
285
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_review'",
|
|
286
|
+
(tools.run_id,),
|
|
287
|
+
)
|
|
288
|
+
]
|
|
289
|
+
reports = [
|
|
290
|
+
json.loads(r["payload_json"])
|
|
291
|
+
for r in db.execute(
|
|
292
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='editorial_review' ORDER BY sequence",
|
|
293
|
+
(tools.run_id,),
|
|
294
|
+
)
|
|
295
|
+
]
|
|
296
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
297
|
+
offsets = []
|
|
298
|
+
recipe_id = render_recipe_id()
|
|
299
|
+
for entry in entries:
|
|
300
|
+
if entry["revision_id"] != revision.revision_id or entry.get("recipe_id") != recipe_id:
|
|
301
|
+
continue
|
|
302
|
+
saved = store.get(tools.project_id, entry["render_id"])
|
|
303
|
+
path = store.output_path(tools.project_id, entry["render_id"], prepare=False)
|
|
304
|
+
if (
|
|
305
|
+
saved["state"] == "succeeded"
|
|
306
|
+
and not path.is_symlink()
|
|
307
|
+
and path.is_file()
|
|
308
|
+
and path.stat().st_size == saved["size_bytes"]
|
|
309
|
+
):
|
|
310
|
+
offsets.extend(entry["offsets_seconds"])
|
|
311
|
+
fps = revision.timeline.frame_rate.numerator / revision.timeline.frame_rate.denominator
|
|
312
|
+
|
|
313
|
+
def seen(target):
|
|
314
|
+
return any(abs(o - target) < 0.45 / fps for o in offsets)
|
|
315
|
+
|
|
316
|
+
# Shots and texts accepted in an earlier review and unchanged since need no new stills.
|
|
317
|
+
from .editorial_review import carried_reviews
|
|
318
|
+
|
|
319
|
+
carried_shots, carried_texts = carried_reviews(tools, revision, recipe_id)
|
|
320
|
+
missing_shots = {
|
|
321
|
+
identifier: [o for o in samples if not seen(o)]
|
|
322
|
+
for identifier, samples in coverage_targets(revision.timeline).items()
|
|
323
|
+
if identifier not in carried_shots
|
|
324
|
+
}
|
|
325
|
+
missing_shots = {k: v for k, v in missing_shots.items() if v}
|
|
326
|
+
missing_texts = {k: v for k, v in text_targets(revision.timeline).items() if k not in carried_texts and not seen(v)}
|
|
327
|
+
complete = not missing_shots and not missing_texts
|
|
328
|
+
report = next(
|
|
329
|
+
(r for r in reversed(reports) if r["revision_id"] == revision.revision_id and r.get("recipe_id") == recipe_id),
|
|
330
|
+
None,
|
|
331
|
+
)
|
|
332
|
+
unresolved = (
|
|
333
|
+
[]
|
|
334
|
+
if report is None
|
|
335
|
+
else [s["item_id"] for s in report["shots"] if s["decision"] == "revise"]
|
|
336
|
+
+ [c["item_id"] for c in report["text_checks"] if not c["matches"]]
|
|
337
|
+
)
|
|
338
|
+
return {
|
|
339
|
+
"reviewed_revision": complete and report is not None and not unresolved,
|
|
340
|
+
"render_coverage_complete": complete,
|
|
341
|
+
"missing_shots": missing_shots,
|
|
342
|
+
"missing_texts": missing_texts,
|
|
343
|
+
"editorial_assessment_recorded": report is not None,
|
|
344
|
+
"unresolved": unresolved,
|
|
345
|
+
"carried_shots": sorted(carried_shots),
|
|
346
|
+
"carried_texts": sorted(carried_texts),
|
|
347
|
+
"carried_note": "Unchanged shots and texts accepted in an earlier review of this run; review_cut may omit them.",
|
|
348
|
+
"coverage": "start/middle/end rendered stills and text samples; continuous motion and audio not reviewed",
|
|
349
|
+
"assessment_authority": "model_authored",
|
|
350
|
+
"human_review": "pending",
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def cancel_preview(tools, args):
|
|
355
|
+
with tools.repository.projects.connect(tools.project_id) as db:
|
|
356
|
+
entries = [
|
|
357
|
+
json.loads(r["payload_json"])
|
|
358
|
+
for r in db.execute(
|
|
359
|
+
"SELECT payload_json FROM edit_agent_events WHERE run_id=? AND event_type='production_preview'",
|
|
360
|
+
(tools.run_id,),
|
|
361
|
+
)
|
|
362
|
+
]
|
|
363
|
+
if not any(e["render_id"] == args["render_id"] for e in entries):
|
|
364
|
+
raise ProjectError("preview_not_found", "預覽不屬於這次剪輯。", status_code=404)
|
|
365
|
+
store = PreviewRenderRepository(tools.repository.projects)
|
|
366
|
+
saved = store.get(tools.project_id, args["render_id"])
|
|
367
|
+
if saved["state"] not in {"queued", "running", "cancelling"}:
|
|
368
|
+
return ToolResult({"render": saved})
|
|
369
|
+
store.request_cancel(tools.project_id, args["render_id"])
|
|
370
|
+
job = getattr(tools, "_preview_jobs", {}).get(args["render_id"])
|
|
371
|
+
if job:
|
|
372
|
+
job[0].set()
|
|
373
|
+
return ToolResult({"render": store.get(tools.project_id, args["render_id"])})
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"""Bounded, factual activity for the production UI; no inferred completion rates.
|
|
2
|
+
|
|
3
|
+
Stages report how far the AI has observably got, never a percentage of the
|
|
4
|
+
work: an agent revisits steps and has no fixed number of them.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
_TOOL_GROUPS = (
|
|
10
|
+
(
|
|
11
|
+
"理解製作需求與影片風格",
|
|
12
|
+
(
|
|
13
|
+
"get_edit_status",
|
|
14
|
+
"list_editing_tools",
|
|
15
|
+
"list_production_skills",
|
|
16
|
+
"read_production_skill",
|
|
17
|
+
"list_program_components",
|
|
18
|
+
),
|
|
19
|
+
),
|
|
20
|
+
(
|
|
21
|
+
"尋找與檢視來源素材",
|
|
22
|
+
(
|
|
23
|
+
"list_source_media",
|
|
24
|
+
"search_media",
|
|
25
|
+
"search_source_dialogue",
|
|
26
|
+
"register_source_range",
|
|
27
|
+
"sample_source",
|
|
28
|
+
"inspect_candidates",
|
|
29
|
+
"inspect_clip",
|
|
30
|
+
),
|
|
31
|
+
),
|
|
32
|
+
("準備本機語音模型", ("prepare_local_speech",)),
|
|
33
|
+
(
|
|
34
|
+
"辨識與對齊來源口語",
|
|
35
|
+
("transcribe_source_range", "align_source_speech", "revise_source_speech", "list_transcripts"),
|
|
36
|
+
),
|
|
37
|
+
(
|
|
38
|
+
"安排故事與剪輯",
|
|
39
|
+
(
|
|
40
|
+
"record_story_plan",
|
|
41
|
+
"read_story_plan",
|
|
42
|
+
"plan_episode",
|
|
43
|
+
"replace_sequence",
|
|
44
|
+
"replace_clip_source",
|
|
45
|
+
"trim_clip",
|
|
46
|
+
"reorder_clips",
|
|
47
|
+
"split_clip",
|
|
48
|
+
"insert_clip",
|
|
49
|
+
"set_canvas",
|
|
50
|
+
"remove_item",
|
|
51
|
+
),
|
|
52
|
+
),
|
|
53
|
+
(
|
|
54
|
+
"製作字幕與畫面設計",
|
|
55
|
+
(
|
|
56
|
+
"replace_subtitles",
|
|
57
|
+
"remove_program_component",
|
|
58
|
+
"add_custom_component",
|
|
59
|
+
"update_custom_component",
|
|
60
|
+
"set_component_look",
|
|
61
|
+
"set_color_grade",
|
|
62
|
+
"set_mosaic",
|
|
63
|
+
"set_transition",
|
|
64
|
+
"set_fade",
|
|
65
|
+
"add_effect",
|
|
66
|
+
"remove_clip_effect",
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
(
|
|
70
|
+
"尋找與安排配樂、音效",
|
|
71
|
+
(
|
|
72
|
+
"search_music",
|
|
73
|
+
"list_audio_assets",
|
|
74
|
+
"extract_audio",
|
|
75
|
+
"inspect_audio",
|
|
76
|
+
"place_audio",
|
|
77
|
+
"remove_audio",
|
|
78
|
+
"set_source_audio",
|
|
79
|
+
),
|
|
80
|
+
),
|
|
81
|
+
("輸出樣片預覽", ("render_preview",)),
|
|
82
|
+
(
|
|
83
|
+
"檢查畫面、字幕與聲音",
|
|
84
|
+
("inspect_preview", "inspect_cut", "review_cut", "validate_sequence", "inspect_mix", "inspect_pacing"),
|
|
85
|
+
),
|
|
86
|
+
("等待或處理本機工作結果", ("read_evidence_job", "retry_evidence_job", "cancel_evidence_job")),
|
|
87
|
+
("整理交付檔案", ("export_edit", "finish_edit")),
|
|
88
|
+
)
|
|
89
|
+
_TOOL_LABELS = {tool: label for label, tools in _TOOL_GROUPS for tool in tools}
|
|
90
|
+
_EVENT_LABELS = {
|
|
91
|
+
"run_created": "製作工作已建立",
|
|
92
|
+
"run_started": "AI 已開始製作",
|
|
93
|
+
"refinement_requested": "收到你的修改要求",
|
|
94
|
+
"run_resumed": "接續上次的草稿",
|
|
95
|
+
"provider_switched": "換另一個 AI 接手",
|
|
96
|
+
"revision_created": "草稿已儲存",
|
|
97
|
+
"production_preview": "已提交預覽合成",
|
|
98
|
+
# Reviewing a preview and its mix are the same step to the viewer as the review tools.
|
|
99
|
+
"production_review": "檢查畫面、字幕與聲音",
|
|
100
|
+
"mix_review": "檢查畫面、字幕與聲音",
|
|
101
|
+
"run_finished": "樣片製作已完成,等待你觀看",
|
|
102
|
+
"provider_failed": "AI 這次沒有完成製作",
|
|
103
|
+
"run_cancelled": "製作已停止",
|
|
104
|
+
"run_interrupted": "製作已中斷",
|
|
105
|
+
"budget_exhausted": "本次工作已達操作上限",
|
|
106
|
+
}
|
|
107
|
+
# A failed attempt is described by why it stopped, not as a generic error.
|
|
108
|
+
_FAILURE_LABELS = {
|
|
109
|
+
"delivery_blocked": "AI 做完草稿,但還有項目沒通過檢查",
|
|
110
|
+
"provider_stopped_early": "AI 先停下來了,請看 AI 的說明",
|
|
111
|
+
"provider_usage_limit": "AI 額度不足,暫停製作",
|
|
112
|
+
"provider_timed_out": "超過製作時間上限,暫停製作",
|
|
113
|
+
}
|
|
114
|
+
# The furthest stage reached moves only forward. Checking the cut before any
|
|
115
|
+
# preview is part of editing; reviewing only counts once a film was rendered.
|
|
116
|
+
STAGES = ("understand", "sources", "edit", "graphics", "music", "render", "review")
|
|
117
|
+
_STAGE_OF_LABEL = {
|
|
118
|
+
"理解製作需求與影片風格": "understand",
|
|
119
|
+
"尋找與檢視來源素材": "sources",
|
|
120
|
+
"準備本機語音模型": "sources",
|
|
121
|
+
"辨識與對齊來源口語": "sources",
|
|
122
|
+
"安排故事與剪輯": "edit",
|
|
123
|
+
"製作字幕與畫面設計": "graphics",
|
|
124
|
+
"尋找與安排配樂、音效": "music",
|
|
125
|
+
"輸出樣片預覽": "render",
|
|
126
|
+
"已提交預覽合成": "render",
|
|
127
|
+
"檢查畫面、字幕與聲音": "review",
|
|
128
|
+
"整理交付檔案": "review",
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _stages(labels, finished):
|
|
133
|
+
furthest, rendered = -1, False
|
|
134
|
+
for label in labels:
|
|
135
|
+
stage = _STAGE_OF_LABEL.get(label)
|
|
136
|
+
if stage is None:
|
|
137
|
+
continue
|
|
138
|
+
if stage == "render":
|
|
139
|
+
rendered = True
|
|
140
|
+
if stage == "review" and not rendered:
|
|
141
|
+
stage = "edit"
|
|
142
|
+
furthest = max(furthest, STAGES.index(stage))
|
|
143
|
+
if finished:
|
|
144
|
+
furthest = len(STAGES)
|
|
145
|
+
return {"stages": STAGES, "reached": furthest}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# Each request (a new film, a revision, a resume) starts a fresh activity list.
|
|
149
|
+
_STARTS = ("run_created", "refinement_requested", "run_resumed")
|
|
150
|
+
_SHOWN = 10
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _duration(seconds):
|
|
154
|
+
minutes = max(1, round(seconds / 60))
|
|
155
|
+
return f"{minutes} 分鐘" if minutes < 60 else f"{minutes // 60} 小時 {minutes % 60} 分鐘"
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _provider_name(provider_id):
|
|
159
|
+
from clipen.provider_registry import get_provider
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
return get_provider(provider_id).display_name
|
|
163
|
+
except (KeyError, ValueError, TypeError):
|
|
164
|
+
return "AI"
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _latest_start(database, run_id, kinds):
|
|
168
|
+
return database.execute(
|
|
169
|
+
f"SELECT COALESCE(MAX(sequence),0) FROM edit_agent_events WHERE run_id=? AND event_type IN ({','.join('?' for _ in kinds)})",
|
|
170
|
+
(run_id, *kinds),
|
|
171
|
+
).fetchone()[0]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def production_activity(database, run_id):
|
|
175
|
+
boundary = _latest_start(database, run_id, _STARTS)
|
|
176
|
+
# Resuming continues the same request, so its stages carry on from before.
|
|
177
|
+
request_boundary = _latest_start(database, run_id, ("run_created", "refinement_requested"))
|
|
178
|
+
kinds = ("tool_called", "provider_finished", "machine_slept", *_EVENT_LABELS)
|
|
179
|
+
placeholders = ",".join("?" for _ in kinds)
|
|
180
|
+
rows = database.execute(
|
|
181
|
+
f"SELECT sequence,event_type,payload_json,created_at FROM edit_agent_events "
|
|
182
|
+
f"WHERE run_id=? AND sequence>=? AND event_type IN ({placeholders}) ORDER BY sequence",
|
|
183
|
+
(run_id, request_boundary, *kinds),
|
|
184
|
+
).fetchall()
|
|
185
|
+
activity, message, request, labels, finished, slept = [], None, None, [], False, 0
|
|
186
|
+
started_at = next((row["created_at"] for row in rows if row["sequence"] >= boundary), None)
|
|
187
|
+
for row in rows:
|
|
188
|
+
payload = json.loads(row["payload_json"])
|
|
189
|
+
kind = row["event_type"]
|
|
190
|
+
finished = finished or kind == "run_finished"
|
|
191
|
+
if kind in {"provider_finished", "provider_failed"} and row["sequence"] >= boundary:
|
|
192
|
+
message = payload.get("message") or message
|
|
193
|
+
if kind == "provider_finished":
|
|
194
|
+
continue
|
|
195
|
+
if kind == "refinement_requested":
|
|
196
|
+
request = payload.get("instruction")
|
|
197
|
+
tool = payload.get("tool", "") if kind == "tool_called" else None
|
|
198
|
+
if kind == "tool_called":
|
|
199
|
+
label = _TOOL_LABELS.get(tool, "AI 正在操作剪輯工具")
|
|
200
|
+
elif kind == "provider_failed":
|
|
201
|
+
label = _FAILURE_LABELS.get(payload.get("error_code"), _EVENT_LABELS[kind])
|
|
202
|
+
elif kind == "machine_slept":
|
|
203
|
+
if row["sequence"] >= boundary:
|
|
204
|
+
slept += payload.get("seconds", 0)
|
|
205
|
+
label = f"Mac 睡眠約 {_duration(payload.get('seconds', 0))},製作暫停"
|
|
206
|
+
elif kind == "provider_switched":
|
|
207
|
+
label = f"改由 {_provider_name(payload.get('to'))} 接手修改"
|
|
208
|
+
else:
|
|
209
|
+
label = _EVENT_LABELS[kind]
|
|
210
|
+
labels.append(label)
|
|
211
|
+
if row["sequence"] < boundary:
|
|
212
|
+
continue
|
|
213
|
+
# Many tool calls in a row are one step to the viewer; keep its latest time.
|
|
214
|
+
if activity and activity[-1]["label"] == label:
|
|
215
|
+
activity[-1].update(sequence=row["sequence"], created_at=row["created_at"], count=activity[-1]["count"] + 1)
|
|
216
|
+
continue
|
|
217
|
+
activity.append(
|
|
218
|
+
{
|
|
219
|
+
"sequence": row["sequence"],
|
|
220
|
+
"kind": kind,
|
|
221
|
+
"label": label,
|
|
222
|
+
"tool": tool,
|
|
223
|
+
"created_at": row["created_at"],
|
|
224
|
+
"count": 1,
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
activity = activity[-_SHOWN:]
|
|
228
|
+
return {
|
|
229
|
+
"activity": activity,
|
|
230
|
+
"updated_at": activity[-1]["created_at"] if activity else None,
|
|
231
|
+
"ai_message": message,
|
|
232
|
+
"request": request,
|
|
233
|
+
"started_at": started_at,
|
|
234
|
+
"slept_seconds": slept,
|
|
235
|
+
**_stages(labels, finished),
|
|
236
|
+
}
|